Segmentation fault in PHP loop

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
durham86

Segmentation fault in PHP loop

Post by durham86 »

Hello Everyone!

I've written the following PHP code you use ImageMagick to create a thumbnail of every photo in a directory. It's runing on a Apache server.

Loop Code Extract:

foreach ($photofile as $value)
{
$clientphotos['image'] = $value;
$image = "/usr/home/admin/domains/designjunkie.com/public_html/test/web/photoshoots/".$clientphotos['shootid']."/".$clientphotos['image'];
$thumbname = "/usr/home/admin/domains/designjunkie.com/public_html/test/web/photoshoots/".$clientphotos['shootid']."/thumbnails/".$clientphotos['image'];

system("\"/usr/local/bin/convert\" -thumbnail 170x120 $image $thumbname");
}

The problem i have is that it seems to complete the first cycle and it creates a thumbnail of the first photo then for the second photo onwards it returns a Segmentation fault error. Its works fine on my local machine but not on the live server.

Thanks

Durham
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Segmentation fault in PHP loop

Post by anthony »

Try to simplify, get error outputs, check version numbers. Print the exact command that is being run, etc etc etc
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
durham86

Re: Segmentation fault in PHP loop

Post by durham86 »

I've tried doing that - everything seems to work apart from the convert command always brings up a Segmentation fault for the second item onwards.

It works fines with just one item.

I'm using Version: ImageMagick 6.3.5 10/16/07 Q16 if that helps?

Even if i take it out of the loop and put the following for each photo (changing it from photo1.jpg to photo2.jpg etc..) it will still only do the first photo and then bring the Segmentation fault for the others:

$image = "/usr/home/admin/domains/designjunkie.com/public_html/test/web/photoshoots/50/photo1.jpg";
$thumbname = "/usr/home/admin/domains/designjunkie.com/public_html/test/web/photoshoots/50/thumbnails/photo1.jpg";

system("\"/usr/local/bin/convert\" -thumbnail 170x120 $image $thumbname");
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Segmentation fault in PHP loop

Post by Bonzo »

What happens if you use this ?

Code: Select all

$image = "/usr/home/admin/domains/designjunkie.com/public_html/test/web/photoshoots/50/photo1.jpg";
$thumbname = "/usr/home/admin/domains/designjunkie.com/public_html/test/web/photoshoots/50/thumbnails/photo1.jpg";
$array = array();
exec("/usr/local/bin/convert $image -thumbnail 170x120 $thumbname 2>&1", $array); 
echo "<br>".print_r($array)."<br>";
Are these image paths correct? It looks like you have 2 paths from root in the same path. I would have thought public_html/test/web/photoshoots/50/photo1.jpg would have done.
What you could do as well is ceate a tempory folder with some images and the code in to prove it works then modify it to what you want.
I use relative paths in my code and that works OK.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Segmentation fault in PHP loop

Post by anthony »

durham86 wrote:

Code: Select all

system("\"/usr/local/bin/convert\" -thumbnail 170x120 $image $thumbname");
You have checked for error output haven't you?

What if you just convert the file, without the -thumbnail resize?
Does that segmentation fault?

What about

Code: Select all

system("\"/usr/local/bin/convert\" rose: $thumbname");
If these that later does not segmentfault but the former does, then you probably have an image that causes a problem for IM. That image should be submitted to the bug forum for further checking. As I mentions IM should NEVER segment fault. It should do either nothing, or in this case produce an error.

ASIDE: -thumbnail operator should be AFTER reading the image. It should be thought of as an operator and not a UNIX command option.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply