Brand new to IM, known about it for ages, but finally decided to take the plunge, looks good so far.
Having seen the comand line code below I want to convert it into PHP.
I must be doing something wrong, I've checked the help pages but can't find out how to do this.
convert logo: \
-resize x160 -resize '160x<' -resize 50% \
-gravity center -crop 80x80+0+0 +repage space_fill.jpg
exec("convert test/68a.jpg: \
-resize x160 -resize '160x<' -resize 50% \
-gravity center -crop 80x80+0+0 +repage done/68a.jpg",$report);
print_r($report);
I've managed to so simple things like:
system('convert "test/68b.jpg" -resize 400 "done/68b.jpg"');
Thanks for reading.
PHP exec resize
Re: PHP exec resize
As you are going over multiple lines and using php you need \\ not just \ as the \ needs "escaping".
test/68a.jpg: does not need the : at the end; this is only for ImageMagick built in image.
You have resize three times why ?
Try:
test/68a.jpg: does not need the : at the end; this is only for ImageMagick built in image.
You have resize three times why ?
Try:
Code: Select all
exec("convert test/68a.jpg -resize 50% \\
-gravity center -crop 80x80+0+0 +repage done/68a.jpg",$report);
print_r($report);
Re: PHP exec resize
The first two resizes test the image so that the crop image is as large as possible when cropped. So that the image can fill any shape and keep the ratio.
That exec() didn't work for me.
http://www.imagemagick.org/Usage/resize/#space_fill
convert logo: \
-resize x160 -resize '160x<' -resize 50% \
-gravity center -crop 80x80+0+0 +repage space_fill.jpg
That exec() didn't work for me.
http://www.imagemagick.org/Usage/resize/#space_fill
convert logo: \
-resize x160 -resize '160x<' -resize 50% \
-gravity center -crop 80x80+0+0 +repage space_fill.jpg
Re: PHP exec resize
I didn't know about the resize to fill a space; but then again there is a lot I do not know
Did you use my modified code ?
Try:
Did you use my modified code ?
Try:
Code: Select all
exec("convert test/68a.jpg \\
-resize x160 -resize '160x<' -resize 50% \\
-gravity center -crop 80x80+0+0 +repage done/68a.jpg",$report);
print_r($report);
Re: PHP exec resize
That was the feature that convinced me to have a good look at IM.
Tried both modified codes still no image and the array is blank.
Tried both modified codes still no image and the array is blank.
Re: PHP exec resize
I would try putting the code all onto one line then changing your error reporting to this and see what you get.
One thing I have just noticed is your crop could be the same size as your image so the code could fail on that. You may get an image but not what you expect.
Code: Select all
exec("convert test/68a.jpg -resize x160 -resize '160x<' -resize 50% -gravity center -crop 80x80+0+0 +repage done/68a.jpg 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
Re: PHP exec resize
I was just using the sample resizes to get it working, that 80x80, 160 50% is taken straight from the site, so I expect it should work, they've got the sample image next to it.
That still returns an empty array.
I was just browing your site, you can do some great stuff with IM. Like the sunflower one.
Maybe it might be easier to do the maths, then resize and then crop. So PHP does more of the work?
That still returns an empty array.
I was just browing your site, you can do some great stuff with IM. Like the sunflower one.
Maybe it might be easier to do the maths, then resize and then crop. So PHP does more of the work?
Re: PHP exec resize
Your syntax is wrong. Try this:
$cmd_debug= (TRUE)? '-debug exception' : ''; //or false; the '' is two single quote marks. A NULL should work also
$command= "IM command string"; //your string on a single line
$file //php path rule to file
exec("convert $cmd_debug $command $file", $IMarray, $code);
print_r($IMarray);
Actually, I recommend using Imagick, the php extension. Syntax is much easier to deal with.
$cmd_debug= (TRUE)? '-debug exception' : ''; //or false; the '' is two single quote marks. A NULL should work also
$command= "IM command string"; //your string on a single line
$file //php path rule to file
exec("convert $cmd_debug $command $file", $IMarray, $code);
print_r($IMarray);
Actually, I recommend using Imagick, the php extension. Syntax is much easier to deal with.
Re: PHP exec resize
Interesting piece of code ridera; would you mind if I put it on my website ?
Anyway running the code of ridera's and mine I generate an image with both lots of code but with mine I output a "1" which is a fail. Although it does create an image but the error array in both cases is empty.
Array
(
)
Array ( )
1
Thats interesting if I echo $code; in rideras example it outputs 0 which is success !
Array
(
)
0
Array ( )
1
Are the 1 returned and the 0 returned the same thing ?
Anyway running the code of ridera's and mine I generate an image with both lots of code but with mine I output a "1" which is a fail. Although it does create an image but the error array in both cases is empty.
Array
(
)
Array ( )
1
Code: Select all
<?php
$cmd_debug= (TRUE)? '-debug exception' : ''; //or false; the '' is two single quote marks. A NULL should work also
$command= "sunflower.jpg -resize x160 -resize \"160x<\" -resize 50% -gravity center -crop 80x80+0+0 +repage"; //your string on a single line
$file = "68a.jpg";//php path rule to file
exec("convert $cmd_debug $command $file", $IMarray, $code);
echo "<pre>";
print_r($IMarray);
echo "</pre>";
exec("convert sunflower.jpg -resize x160 -resize \"160x<\" -resize 50% -gravity center -crop 80x80+0+0 +repage 168a.jpg 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
?>
Array
(
)
0
Array ( )
1
Are the 1 returned and the 0 returned the same thing ?