In PHP, exec("convert") won't work
Posted: 2007-03-07T18:41:15-07:00
I am trying to run ImageMagick's convert program from within a PHP script, with frustrating results. I need to convert an image from .PNG to .GIF format. I have tried the following:
(The image.png file is in the same directory as the php script).
I thought this code would at least output something useful to the page when run in the browser, but I get nothing. Eventually, I found the following output:
in the Apache log file /private/var/log/httpd/error_log. I don't believe that ImageMagick doesn't have a decode delegate for .png format. For a start, I am able to convert from .PNG to .GIF when I run convert at the command line. Just to double-check, I ran the following at the command line
Which output:
And out of interest, I tried running the following PHP:
Which output the following when loaded in the browser:
i.e. Nothing! Incidentally, if I change the php code above to
then, on running it in the browser, the page is filled with exactly the same messsage as I would get if I just execute 'identify' or 'convert' on the command line with no arguments.
I'm pretty confused as to what all of this means. It seems as though PHP is capable of running the programs at their very simplest (ie with no arguments), but can't cope when options or arguments are added.
I've googled to find that others have had similar problems (e.g. ImageMagick working on command line, but not from PHP with exec() call), but none of the solutions given have helped me. Here are some details which may be relevant:
And if you're still reading, thanks.
Code: Select all
<?php
$input = "image.png";
$output = "image.gif";
$convert = "/usr/local/bin/convert";
$command = "$convert $input $output";
exec($command, $return);
foreach ($return as $val){
echo "<br/>".$val;
}
?>
I thought this code would at least output something useful to the page when run in the browser, but I get nothing. Eventually, I found the following output:
convert: no decode delegate for this image format `image.png'.
convert: missing an image filename `image.gif'.
in the Apache log file /private/var/log/httpd/error_log. I don't believe that ImageMagick doesn't have a decode delegate for .png format. For a start, I am able to convert from .PNG to .GIF when I run convert at the command line. Just to double-check, I ran the following at the command line
Code: Select all
identify -list format
Format Module Mode Description
-------------------------------------------------------------------------------
A* RAW rw+ Raw alpha samples
ART* ART r-- PFS: 1st Publisher
...
GIF* GIF rw+ CompuServe graphics interchange format
...
PNG* PNG rw- Portable Network Graphics (libpng 1.2.12)
...
* native blob support
And out of interest, I tried running the following PHP:
Code: Select all
<?php
$command = "/usr/local/bin/identify -list format";
exec($command, $return);
foreach ($return as $val){
echo "<br/>".$val;
}
?>
Format Module Mode Description
-------------------------------------------------------------------------------
* native blob support
i.e. Nothing! Incidentally, if I change the php code above to
Code: Select all
$command = "/usr/local/bin/identify";
// *or*
$command = "/usr/local/bin/convert";
I'm pretty confused as to what all of this means. It seems as though PHP is capable of running the programs at their very simplest (ie with no arguments), but can't cope when options or arguments are added.
I've googled to find that others have had similar problems (e.g. ImageMagick working on command line, but not from PHP with exec() call), but none of the solutions given have helped me. Here are some details which may be relevant:
- PHP is not running in safe mode.
- In PHP, open_basedir is not set (discussed here: viewtopic.php?f=10&t=7267)
- I also searched the httpd.conf file for the string "open_basedir", which returned 0 results.
- Permissions for convert, by ls -l /usr/local/bin/convert are:
-rwxr-xr-x 1 root admin 34656 Sep 24 19:00 /usr/local/bin/convert
(discussed here: http://www.webhostingtalk.com.au/archiv ... -3401.html)
And if you're still reading, thanks.