Page 1 of 1

"convert" command works from command line, but not from web

Posted: 2009-09-24T15:15:10-07:00
by imgguy
I can't get the "convert" command to work from within a PHP script, when executed from the web. When I execute the PHP script from the command line, it works fine.

I've pared it down to a very simple script:

Code: Select all

<?php
system("/usr/bin/convert input.jpg output.png");
?>
When executed from the web, "output.png" never gets created.

I ran the debug script on Rubblewebs.co.uk. It looks like this is the problem:
"convert: unable to open image `output.png': Permission denied."
input.jpg, and the directory in which it's located, are both 777. What's the next troubleshooting step for me? Thanks.

Re: "convert" command works from command line, but not from web

Posted: 2009-09-25T04:30:27-07:00
by Bonzo
Your problem indicates there could be a problem with the setup or a path.

Before you contact your hosts try running these two codes and see what you get:

Code: Select all

<?php
echo "<pre>";
system("type convert"); 
echo "</pre>";
?> 
This should give you something like
convert is /usr/local/bin/convert

Code: Select all

<?php
echo "<pre>";
system("convert -version");  
echo "</pre>";
?> 
Should return something like:
Version: ImageMagick 6.3.4 05/11/07 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2007 ImageMagick Studio LLC
You only need to use system if you are expecting something to be printed; most of the time you can use exec does that make a difference?

Re: "convert" command works from command line, but not from web

Posted: 2009-09-26T12:21:42-07:00
by imgguy
Thanks for the reply Bonzo.

I ran the two codes as you suggested. The first one returned:
convert is /usr/bin/convert
The second one returned:
Version: ImageMagick 6.4.0 07/27/08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC
I also tried using exec instead of system, and it didn't make a difference.

Re: "convert" command works from command line, but not from web

Posted: 2009-09-27T11:48:08-07:00
by Bonzo
I wonder if you have png support ?

Try a resize and save as a jpg instead of a png.

This code should show details of your setup:

Code: Select all

<?php
// Build the array of items to be used
exec("convert convert -list list", $IMarray, $code);
// Start the loop to find and display the results
foreach ($IMarray as $value) {
echo "<br>system (\"convert -list $value\")";
echo "<pre>";
system("convert -list $value");
echo "</pre><hr>";
}
?>
About half way down the readout in the "system ("convert -list Format")" section you should find something like:
PLASMA* PLASMA r-- Plasma fractal image
PNG* PNG rw- Portable Network Graphics (libpng 1.2.38)
See http://www.libpng.org/ for details about the PNG format.
PNG24* PNG rw- opaque 24-bit RGB (zlib 1.2.3)
PNG32* PNG rw- opaque or transparent 32-bit RGBA
PNG8* PNG rw- 8-bit indexed with optional binary transparency
PNM* PNM rw+ Portable anymap
r = Read
w= Write

Re: "convert" command works from command line, but not from web

Posted: 2009-09-30T11:38:32-07:00
by imgguy
Thanks again Bonzo.

It looks like I do indeed have png support. I tried a resize, and saved as a jpg. Same result -- it worked from the command line, but not from the web.

Here's the relevant output from the script you posted:
PLASMA* PLASMA r-- Plasma fractal image
PNG* PNG rw- Portable Network Graphics (libpng 1.2.29,1.2.37)
See http://www.libpng.org/ for details about the PNG format.
PNG24* PNG rw- opaque 24-bit RGB (zlib 1.2.3)
PNG32* PNG rw- opaque or transparent 32-bit RGBA
PNG8* PNG rw- 8-bit indexed with optional binary transparency
PNM* PNM rw+ Portable anymap
So, it looks like ImageMagick can read and write png files. Could this be some sort of Apache permissions issue, as it works from the command line, but not from a web browser?

Re: "convert" command works from command line, but not from web

Posted: 2009-09-30T14:23:28-07:00
by Bonzo
I would contact your hosts and see what they say; I am afraid that I have no other ideas.