Page 1 of 1

convert strings run by php's exec give weird errors

Posted: 2008-10-22T05:27:38-07:00
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.

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

Posted: 2008-10-22T07:50:55-07:00
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);

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

Posted: 2008-10-22T08:29:33-07:00
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 :)