Page 1 of 1

Segmentation fault in PHP loop

Posted: 2007-10-16T09:26:34-07:00
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

Re: Segmentation fault in PHP loop

Posted: 2007-10-16T19:24:02-07:00
by anthony
Try to simplify, get error outputs, check version numbers. Print the exact command that is being run, etc etc etc

Re: Segmentation fault in PHP loop

Posted: 2007-10-17T01:31:28-07:00
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");

Re: Segmentation fault in PHP loop

Posted: 2007-10-17T02:45:27-07:00
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.

Re: Segmentation fault in PHP loop

Posted: 2007-10-17T17:21:41-07:00
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.