View Full Version : can't create simple image from php exec , can create with the same command standalone

11-30-2010, 03:40 PM
I have this code running in CentOS 5.5 ,PHP 5.1.6 ,Apache/2.2.3 ,ImageMagick 6.2.8

$convert = "/usr/bin/convert";
$command = "$convert -size 100x100 xc:blue mytest.jpg";
$test_image = exec($command);
echo "<img src=\"mytest.jpg\">";

when i run the php tester i dont get the image created , only the echo string printed on page as html.
but when i run the same command as onliner the image does created just fine.

/usr/bin/convert -size 100x100 xc:blue mytest.jpg
what is wrong here i can't tell.

11-30-2010, 09:19 PM
Enable error_reporting and see what error message you get. Personally, I'm guessing user:group permissions.

11-30-2010, 10:39 PM
The description for the problem actually sounds like its being served as text/plain.
At the top of your page, try adding an html header:

header("Content-type: text/html");

I assumed that your output was:

<img src="mytest.jpg" />

and not

echo "<img src=\"mytest.jpg\" />";


Also, be warned that exec() is often disabled for security reasons. If it is, you can use the PHP GD Library to alter your graphics.

12-01-2010, 04:48 AM
before the html