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

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
SEO

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

Post 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!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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");
SEO

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

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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.
SEO

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

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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.
SEO

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

Post by SEO »

I am not seeing any errors, I believe error reporting for exec()/system() calls is disabled for security reasons.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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"); 

?> 
SEO

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

Post 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! :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

FYI:

The ^ for resize was added in version 6.3.8-2 according to the changelog
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply