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

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
imgguy

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

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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?
imgguy

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

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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
imgguy

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

Post 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?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post by Bonzo »

I would contact your hosts and see what they say; I am afraid that I have no other ideas.
Post Reply