convert strings run by php's exec give weird errors

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
avothecat

convert strings run by php's exec give weird errors

Post by avothecat »

if I run this in command prompt:

Code: Select all

convert -resize 71x100! "c:/webserver/images/users/avo/artworks/1.png" "c:/webserver/images/users/avo/thumbnails/1.png"
it runs perfectly fine. it generates a nice thumbnail, and ends up at the correct location.
However, if I try to run it with php's exec, even going as far as to literally entering the above, trying each combination of escaping things out etc, no thumbnail is generated, and apache's error log gives me the following line:

Code: Select all

Invalid Parameter - 71x100!
the code executed in php is the following:

Code: Select all

		$query= "convert -resize {$width}x{$height}! \"{$source}\" \"{$destination}\"";
		echo $query;
		exec($query);
Can anyone give me any clues on what causes this weird difference between simple command prompt and exec? : / I run a local webserver so I don't see how there should be much difference.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert strings run by php's exec give weird errors

Post by Bonzo »

Its probably the ! try this first to see if it works:

Code: Select all

$query= "convert $source -resize {$width}x{$height}  $destination";
echo $query;
exec($query);
You need to read the image in first as well.

I wonder if you put the width and height into a variable ?

Code: Select all

$size = $width."x".$height."!";
$query= "convert $source -resize $size  $destination";
echo $query;
exec($query);
avothecat

Re: convert strings run by php's exec give weird errors

Post by avothecat »

Thank you :)

However, leaving the ! out does not help. The error message Apache's error log gives me simply changes to:

Code: Select all

Invalid Parameter - 71x100
instead.

I tried putting the dimensions in a variable as well, no luck.

Reading the image in first,

Code: Select all

	$size = $width."x".$height."!";
	exec("convert \"{$source}\" -resize $size \"{$destination}\"");
Gave me a more interesting error though:

Code: Select all

Invalid Parameter - /users
/users being part of both the source and destination path...
Note that I have to place the "s around the paths because of the occasional spaces in them :P

[edit]
wait wait, something, just created a thumbnail. I didn't see any of that when I tested xD
[edit2]
Yes. Now it works, the above code does it. Not reading in the image first was the problem then. Thanks a lot :)
Post Reply