ImageMagick: convert png fail via PHP and works via bash shell
- by wedix
I've got a very weird bug which I've yet to find a solution. UPDATE see solution below
What I am trying to do is convert a full size picture into a 160x120 thumbnail. It works great with jpg and jpeg files of any size, but not with png.
ImageMagick command:
/opt/local/bin/convert '/WEBSERVER/images/img_0003-192-10.png' -thumbnail x320 -resize '320x<' -resize 50% -gravity center -crop 160x120+0+0 +repage -quality 91 '/WEBSERVER/thumbs/small_img_0003-192-10.png'
PHP function (shortened)
...
$cmd = "/opt/local/bin/convert '/WEBSERVER/images/img_0003-192-10.png' -thumbnail x320 -resize '320x<' -resize 50% -gravity center -crop 160x120+0+0 +repage -quality 91 '/WEBSERVER/thumbs/small_img_0003-192-10.png'";
exec($cmd, $output, $retval);
$errors += $retval;
if ($errors > 0) {
die(print_r($output));
}
When this function runs $retval equal 1 which means the convert command failed (thumbnail isn't created).
This is where it gets interesting, if I run the exact same command in my shell, it works.
wedbook:~ wedix$ /opt/local/bin/convert '/WEBSERVER/images/img_0003-192-10.png' -thumbnail x320 -resize '320x<' -resize 50% -gravity center -crop 160x120+0+0 +repage -quality 91 '/WEBSERVER/thumbs/small_img_0003-192-10.png'
wedbook:~ wedix$
I've tried using different PHP function such as system, passthru but it didn't work. I thought maybe someone here knew the solution.
I'm using
MAMP 1.7.2
Apache/2.0.59
PHP/5.2.6
Thanks!
UPDATE
I updated the following dependencies
libpng from 1.2.35 to 1.2.37
libiconv from 1.12_2 to 1.13_0
ImageMagick 6.5.2-4_1 to 6.5.2-9_0
However, it did not fix my problem.
2nd UPDATE
I finally found something that might help, when the function runs this is what gets printed in the Apache logs:
dyld: Library not loaded: /opt/local/lib/libiconv.2.dylib
Referenced from: /opt/local/bin/convert
Reason: Incompatible library version: convert requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0
3rd UPDATE
libiconv.2.dylib is version 8.0.0...
bash-3.2$ otool -L /opt/local/lib/libiconv.2.dylib
/opt/local/lib/libiconv.2.dylib:
/opt/local/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
4th UPDATE
Problem was related to MAMP, see solution below