Command line use from php fails

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
pnewbold
Posts: 3
Joined: 2012-01-02T15:38:42-07:00
Authentication code: 8675308

Command line use from php fails

Post by pnewbold »

I have installed ImageMagick 6.7.4 Q16 on a machine running Windows Server 2003. I can use it successfully from the command line to resize & rotate images. If I try to use it from a php web page on the machine's Default Web Site via shell_exec() call it fails with the error message:

convert.exe: no delegate for this image 'format xxx.jpg' @error/constitute.c/ReadImage/532.....

shell_exec() is working in other contexts (runs other .exe files OK), and I have given IUSR_xxxx (Internet Guest Account) permission to run convert.exe. I am using the full pathname of convert.exe.

Any ideas what the issue might be?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Command line use from php fails

Post by Bonzo »

What actual code are you running?
pnewbold
Posts: 3
Joined: 2012-01-02T15:38:42-07:00
Authentication code: 8675308

Re: Command line use from php fails

Post by pnewbold »

Not sure what you mean by "what code are you running?". The machine is running php 5.0.3. The test harness I am using is just:

<html>
<head>
<?
$copy = "\"C:\\Program Files\\ImageMagick-6.7.4-Q16\\convert.exe\" F:\\BIG\\kitty1.jpg -rotate 90 -resize 80 F:\\BIG\\smallkitty.jpg 2>&1";
?>
</head>
<body>
<? echo shell_exec($copy); ?>
<br>

</body>
</html>
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Command line use from php fails

Post by Bonzo »

I would have written the code like this on my localhost:

Code: Select all

$copy = "convert BIG/kitty1.jpg -rotate 90 -resize 80 BIG/smallkitty.jpg 2>&1";
Imagemagick is probably working but there could be a problem with the jpg delegate or you could be confusing it.

What does this tell you?

Code: Select all

<?php

// The version installed which will also prove if IM is working
echo "<pre>";
system("convert -version");  
echo "</pre>";

// List all the details of the installation - look to see what it says next to jpg on the delegates section should be something like r/w but its a long time since I looked.
// It should be OK as you can get it to work from the command line
// Build the array of items to be used
exec("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>";
}
?>
pnewbold
Posts: 3
Joined: 2012-01-02T15:38:42-07:00
Authentication code: 8675308

Re: Command line use from php fails

Post by pnewbold »

Additional information: If I execute my php file by invoking php from the command line everything works. It seems to be an issue with the IIS environment. Extracting from your suggested code, system("convert -version") returns an empty string when run via IIS, but using the full pathname for convert results in:

Version: ImageMagick 6.7.4-2 2011-12-22 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

Interestingly the list of delegates does not include jpg, neither when I run the php file through IIS nor when I run it by invoking php from the command line. And yet, using the latter approach, the conversion works just fine.
Post Reply