Geometry suffix does not work in PHP, Linux

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
ciantic
Posts: 8
Joined: 2011-05-07T08:46:43-07:00
Authentication code: 8675308

Geometry suffix does not work in PHP, Linux

Post by ciantic »

Hi!

I know this could be a problem with my PHP, but here goes:

Code: Select all

system("/usr/bin/convert -version"); // ImageMagick 6.6.0-4 2010-11-16 Q16
$output = array();
$rvar = -1;
echo "<pre>";

exec("/usr/bin/convert movie.jpg -thumbnail '50x50>' moviethumb.jpg", $output, $rvar);

var_dump($output, $rvar);
echo "</pre>";
I get

Code: Select all

array(0) {}
int(1)
And no images are created! If I change the '50x50>' to '50x50' it works, but needless to say, I want to use that > modifier. I've tried to escape it escapeshellarg("50x50>") but no help.

If I go with shell to run the same command, it works just fine with the ">" suffix. :shock: It also works just fine under Windows, but the problem is with that Linux box. Can't figure out this...
Last edited by ciantic on 2012-02-27T11:10:52-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Geometry suffix does not work in PHP, Linux

Post by fmw42 »

You probably need to provide the full path to convert in your exec command.

to get your path try

<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>
ciantic
Posts: 8
Joined: 2011-05-07T08:46:43-07:00
Authentication code: 8675308

Re: Geometry suffix does not work in PHP, Linux

Post by ciantic »

fmw42 wrote:You probably need to provide the full path to convert in your exec command.
Didn't work unfortunately. (I put the full path to the parent post) Thanks anyway.

I also noticed that all suffixes fail to work: !^><. Cannot understand this, it reports the version just right and it works just fine from the shell.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Geometry suffix does not work in PHP, Linux

Post by fmw42 »

what version of IM? try replacing -thumbnail with -resize. however, I suspect it is some issue with permission or config in PHP.

try

exec("/usr/bin/convert movie.jpg -thumbnail \"50x50>\" moviethumb.jpg 2>&1", $output, $rvar);

or

exec("/usr/bin/convert movie.jpg -thumbnail 50x50\> moviethumb.jpg 2>&1", $output, $rvar);

I am really puzzled why these special geometry characters won't work in PHP. There should be no reason that they do not if properly quoted or the characters escaped.



Does this even work to copy your input to an output?

exec("/usr/bin/convert movie.jpg moviethumb.jpg 2>&1", $output, $rvar);
ciantic
Posts: 8
Joined: 2011-05-07T08:46:43-07:00
Authentication code: 8675308

Re: Geometry suffix does not work in PHP, Linux

Post by ciantic »

fmw42 wrote:what version of IM?
It's in the parent post, at the comments: ImageMagick 6.6.0-4 2010-11-16 Q16
fmw42 wrote: try
exec("/usr/bin/convert movie.jpg -thumbnail \"50x50>\" moviethumb.jpg 2>&1", $output, $rvar);
exec("/usr/bin/convert movie.jpg -thumbnail 50x50\> moviethumb.jpg 2>&1", $output, $rvar);
Neither work. I have also tried to escape it million ways, no help. I'm more than puzzled, is there something special about the geometry suffixes? Maybe ImageMagick tries to allocate memory differently when using them? And as PHP spwans the process it doesn't work?
fmw42 wrote: Does this even work to copy your input to an output?
exec("/usr/bin/convert movie.jpg moviethumb.jpg 2>&1", $output, $rvar);
That works. But as I said in parent post: the -thumbnail also works just fine if I don't use the "<" suffix, with: -thumbnail 50x50 it works just fine, the result is not what I want though.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Geometry suffix does not work in PHP, Linux

Post by fmw42 »

do you get any error messages from $output

replace the "50x50>" with '50x50>'.

exec("/usr/bin/convert movie.jpg -thumbnail '50x50>' moviethumb.jpg 2>&1", $output, $rvar);

or

size="50x50\>";
exec("/usr/bin/convert movie.jpg -thumbnail " . $size . " moviethumb.jpg 2>&1", $output, $rvar);

See also Anthony's post about quoting twice, if I understand what he is saying, at viewtopic.php?f=1&t=20393#p81406 So something like this perhaps

exec("/usr/bin/convert movie.jpg -thumbnail '\"50x50>\"' moviethumb.jpg 2>&1", $output, $rvar);
Last edited by fmw42 on 2012-02-27T11:49:58-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Geometry suffix does not work in PHP, Linux

Post by fmw42 »

If I go with shell to run the same command, it works just fine with the ">" suffix. It also works just fine under Windows, but the problem is with that Linux box. Can't figure out this...
All I can think of otherwise, is to check with your ISP about the PHP installation and possibly re-install. Perhaps those characters are reserved in your Linux PHP for some odd reason or you are not quoting or escaping them properly. Seems like IM is working fine.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Geometry suffix does not work in PHP, Linux

Post by Bonzo »

I always use " " rather than ' ' but that is mainly as I work on a localhost on my Windows PC and get into the habbit of doing it.

I would write it like this but you have already tried that:

Code: Select all

exec("/usr/bin/convert movie.jpg -thumbnail \"50x50>\" moviethumb.jpg", $output, $rvar);
I am currently rewritting my examples and the only resize arguments I have to quote are the ones with > & <

P.S. It is not something to do with the page encoding? Mine is always in ANSI
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Geometry suffix does not work in PHP, Linux

Post by Bonzo »

Output on my server with Centos OK with 6.4.8
Old version of IM as I do not need anything newer and works OK on my Windows localhost with version 6.7.3
Last edited by Bonzo on 2012-02-27T13:55:42-07:00, edited 1 time in total.
ciantic
Posts: 8
Joined: 2011-05-07T08:46:43-07:00
Authentication code: 8675308

Re: Geometry suffix does not work in PHP, Linux

Post by ciantic »

It cannot be escaping, since:

Code: Select all

exec("convert -pointsize 72 label:'50x50>' movie.jpg");
Produces image with text "50x50>"

Can someone test with php exec safe environment consisting of executables:

Code: Select all

/usr/local/safe$ ls -la
total 320
drwxr-sr-x  2 root root    4096 Jan 31 18:23 .
drwxrwsr-x 17 root staff   4096 Jan 31 18:21 ..
-rwxr-xr-x  1 root root    6032 Jan 31 18:21 animate
-rwx------  1 root root   76582 Jan 31 18:23 cciss_vol_status
-rwxr-xr-x  1 root root    7128 Jan 31 18:21 compare
-rwxr-xr-x  1 root root    6040 Jan 31 18:21 composite
-rwxr-xr-x  1 root root    6032 Jan 31 18:21 conjure
-rwxr-xr-x  1 root root    6032 Jan 31 18:21 convert
-rwxr-xr-x  1 root root    6032 Jan 31 18:21 display
-rwxr-xr-x  1 root root    7136 Jan 31 18:21 identify
-rwxr-xr-x  1 root root    6032 Jan 31 18:21 import
-rwxr-xr-x  1 root root    6032 Jan 31 18:21 mogrify
-rwxr-xr-x  1 root root    6032 Jan 31 18:21 montage
-rwxr-xr-x  1 root root  150648 Jan 31 18:21 unzip
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Geometry suffix does not work in PHP, Linux

Post by Bonzo »

I think you may have to look elsewhere for your answer as Imagemagick works in most of your situations but not with php. I would ask the question on a forum that has more users that know about Linux and servers.
ciantic
Posts: 8
Joined: 2011-05-07T08:46:43-07:00
Authentication code: 8675308

Re: Geometry suffix does not work in PHP, Linux

Post by ciantic »

Bonzo wrote:I think you may have to look elsewhere for your answer as Imagemagick works in most of your situations but not with php. I would ask the question on a forum that has more users that know about Linux and servers.
I doubt it, since it works, it is just that some switches doesn't work like the geometry suffix. If I were to ask elsewhere they'd blame the imagemagick.

Now I tried with mogrify for fun and recreation:

Code: Select all

exec("mogrify -thumbnail '50x50>' movie2.jpg'); // Does not work
//and
exec("mogrify -thumbnail '50x50' movie2.jpg'); // Works
Same problem with that apparently. Both works from the shell though.

Trying the -verbose now:

Code: Select all

system("convert -verbose movie.jpg -thumbnail '50x50>' moviethumb.jpg");
// Does not work, and prints: 
// movie.jpg JPEG 566x89 566x89+0+0 8-bit DirectClass 19.8KB 0.000u 0:00.010

system("convert -verbose movie.jpg -thumbnail '50x50' moviethumb.jpg");
// Works and prints: 
// movie.jpg JPEG 566x89 566x89+0+0 8-bit DirectClass 19.8KB 0.000u 0:00.010
// movie.jpg=>moviethumb.jpg JPEG 566x89=>50x8 8-bit DirectClass 1.080u 0:00.070
This seems to indicate that it is something inside the imagemagick that freezes. Though I quickly skimmed the geometry.c and the parsing of geometry suffix is trivial, as is it's handling. I cannot understand this.

Is there a switch that debugs the command line input?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Geometry suffix does not work in PHP, Linux

Post by fmw42 »

see -debug at http://www.imagemagick.org/Usage/basics/#controls

I am at a loss to explain this considering that others using PHP (e.g. Bonzo) do not have this problem and IM works fine in your terminal. I really suspect it has something to do with your PHP environment. But I am not an expert on PHP and will defer to others.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Geometry suffix does not work in PHP, Linux

Post by anthony »

My feeling is that you are not seeing the error channel. Perhaps it is being logged in the error_log of teh web server.

try redirecting the channel by seting up a specific log for that specific PHP script.
I have not done this myself, but I have notes on it, from the setup of PHP on a webserver.
http://www.ict.griffith.edu.au/anthony/ ... /php.hints

Also have you tried running the PHP from command line to see what it does?

For example... "test.php"

Code: Select all

<?php
  system("convert -verbose logo: -thumbnail '50x50>' result.png");
?>
now run it

Code: Select all

php test.php

Code: Select all

LOGO GIF 640x480 640x480+0+0 8-bit PseudoClass 256c 31.7KB 0.000u 0:00.009
logo:=>LOGO GIF 640x480 640x480+0+0 8-bit PseudoClass 256c 31.7KB 0.000u 0:00.000
logo:=>result.png GIF 640x480=>50x38 8-bit DirectClass 0.020u 0:00.020
STOP PRESS
Looking at the PHP function manual for system()
http://au.php.net/manual/en/function.system.php

Has a major Warning
With safe mode enabled, the command string is escaped with escapeshellcmd(). Thus, echo y | echo x becomes echo y \| echo x.
This means PHP in safe mode may be doing some very unexpected things with the arguments.

Try prepending "echo" to the start (or some other 'list command arguments' program) and see what the argument are actually being received.

ASIDE: it pays to look though comments!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply