Page 1 of 1

resize option flag '^' does not work in PHP?

Posted: 2008-07-04T04:17:55-07:00
by SEO
As it seems the resize option flag '^' does not work within the PHP environment. It does work when the command is executed via SSH shell so it must be related to PHP.

I have tried several commands and right now I am trying the folowing:

exec("convert -size 300x300 ".$image_loc." -thumbnail 100x100^ -gravity center -crop 100x100+0+0 +repage ".$image_loc."");

Is this a bug?

Thanks in advance for your help!

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-04T04:51:46-07:00
by Bonzo
Try enclosing the part of code in " or '

Code: Select all

exec("convert -size 300x300 $image_loc -thumbnail \"100x100^\" -gravity center -crop 100x100+0+0 +repage $image_loc");
or

Code: Select all

exec("convert -size 300x300 $image_loc -thumbnail '100x100^' -gravity center -crop 100x100+0+0 +repage $image_loc");

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-04T05:04:42-07:00
by SEO
Bonzo wrote:Try enclosing the part of code in " or '

Code: Select all

exec("convert -size 300x300 $image_loc -thumbnail \"100x100^\" -gravity center -crop 100x100+0+0 +repage $image_loc");
or

Code: Select all

exec("convert -size 300x300 $image_loc -thumbnail '100x100^' -gravity center -crop 100x100+0+0 +repage $image_loc");
Thank you for your reply! However, I already tried that and I just used your above examples to try it again and it didn't work.

When I try it in SSH it does work for some reason.

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-04T10:43:16-07:00
by Bonzo
When running my first example on my server at home ( XAMPP on windows XP ) the first example I posted worked. But it will not work on the server my site is on; I have tried escaping the ^ and it still will not work.

I wonder if it is a version problem ?

convert: invalid argument for option `100x100^': -resize.

6.4.0 04/16/08 Q16 at home and 6.3.5 08/29/07 Q16 on my server.

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-04T10:48:58-07:00
by SEO
Bonzo wrote:When running my first example on my server at home ( XAMPP on windows XP ) the first example I posted worked. But it will not work on the server my site is on; I have tried escaping the ^ and it still will not work.

I wonder if it is a version problem ?

convert: invalid argument for option `100x100^': -resize.

6.4.0 04/16/08 Q16 at home and 6.3.5 08/29/07 Q16 on my server.
Well, for me the server is already upgraded to the latest version and it does work from shell (SSH). Just not from within PHP.

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-04T11:00:13-07:00
by Bonzo
Do you get the same error as me ?

Code: Select all

echo "<pre>";
$array = array();
exec("convert -size 300x300 $image_loc -resize 100x100^ -gravity center -crop 100x100+0+0 +repage $image_loc 2>&1", $array); 
echo "<pre>";
print_r($array); 
echo "</pre>";
I also tried escaping the ^ with ^ as somebody else had a similar problem and that worked for them but not for me.

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-04T11:02:01-07:00
by SEO
I am not seeing any errors, I believe error reporting for exec()/system() calls is disabled for security reasons.

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-05T01:23:23-07:00
by Bonzo
I can not get anything to work; I think you will have to do a bit more work with php:

Code: Select all

<?php

$size = getimagesize( $image_loc );
if ( $size[0] > $size[1] ){
$size = "x100"; }
else { $size = "100x"; }

$cmd = "-size 300x300 $image_loc -resize $size -gravity center -crop 100x100+0+0 +repage";

exec("convert $cmd $image_loc"); 

?> 

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-05T02:45:34-07:00
by SEO
Bonzo wrote:I can not get anything to work; I think you will have to do a bit more work with php:

Code: Select all

<?php

$size = getimagesize( $image_loc );
if ( $size[0] > $size[1] ){
$size = "x100"; }
else { $size = "100x"; }

$cmd = "-size 300x300 $image_loc -resize $size -gravity center -crop 100x100+0+0 +repage";

exec("convert $cmd $image_loc"); 

?> 
Yes, that seems to be a good solution! I will try it!

Thanks a lot for your help! :)

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-05T08:16:46-07:00
by fmw42
FYI:

The ^ for resize was added in version 6.3.8-2 according to the changelog

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-05T08:29:56-07:00
by Bonzo
I thought it had been around a lot longer than that. As I said in another post it works at home on 6.4.0 04/16/08 Q16 and not 6.3.5 08/29/07 Q16 on my server, that pressumably is why !

At least there is a simple way around it using a bit more php.

Re: resize option flag '^' does not work in PHP?

Posted: 2008-07-09T19:22:18-07:00
by anthony
Also note that ^ is a special character for Windows batch scripts. It may not work as expected for PHP on a windows box.