views:

27

answers:

3

I got 2 seprate Imagemagick commands (resize and crop circle). Is it possible to combine both commands into single PHP exec.

exec('convert original.jpg -resize x100 -gravity center -crop 100x100+0+0 +repage thumbnail.jpg');
exec('convert -size 100x100 xc:none -fill thumbnail.jpg -draw "circle 50,50 50,0" circle.png');

Many thanks

A: 

start a shell in your exec command and supply the executables as parameters to the shell, separated by ';'

e.g. bash -c "ls /tmp/; echo bla"

Marc van Kempen
Won't help the OP: He's asking whether he can combine two ImageMagick operations into one call.
Pekka
No no read carefully, he is asking whether it is possible to combine the two commands in one php exec.
Marc van Kempen
A: 

I can't test this right now, but have you tried simply literally combining them?

exec('convert original.jpg -resize x100 -gravity center -crop 100x100+0+0 +repage
     xc:none -draw "circle 50,50 50,0" circle.png');

(line break added for clarity)

The only thing I'm unsure about is the xc:none as I don't know what that does. Other than that, it should be easy to combine these.

Pekka
A: 

Hi Teon,

Maybe you can chain them with the && operand:

exec('convert original.jpg -resize x100 -gravity center -crop 100x100+0+0 +repage thumbnail.jpg && convert -size 100x100 xc:none -fill thumbnail.jpg -draw "circle 50,50 50,0" circle.png');

Even though that's two calls to convert, it's a single PHP exec call.

Regards

Gastón