Jump to content

system() does not work when command contains parenthesis


eric02138

Recommended Posts

Hi -
Longtime listener, firsttime caller:

I'm having some trouble making a thumbnailing program work.  I'm calling Imagemagick directly using system(), since the GD Library and Imagick aren't available to me.  But when I try to add parenthesis, my code stops working.

The interesting thing is, the output of the code works great on the command line.  It just won't fire from within PHP.  So the following script works in PHP:

****************************************
<?php

$maxsize = 250;
$filepath = "/proj/ramwww/images/article_images/rachel.jpg";
$suffix = "_thm";
$basename = "/proj/ramwww/images/article_images/rachel";

$cmd = "convert $filepath -level 0,90%,1.1 -thumbnail '" . $maxsize
. "x" . $maxsize . ">' " . $basename . $suffix . ".jpg";

echo $cmd . "<br />";

$output = system($cmd);

?>
**********************************************

...but when I try to add a nice drop shadow, it bombs:

**********************************************
<?php

$maxsize = 250;
$filepath = "/proj/ramwww/images/article_images/rachel.jpg";
$suffix = "_thm";
$basename = "/proj/ramwww/images/article_images/rachel";

$cmd = "convert $filepath -level 0,90%,1.1 -thumbnail '" . $maxsize
. "x" . $maxsize . ">' \( +clone -background black -shadow 80x2+3+3 \)
-repage +2+2 +swap -background white -mosaic " . $basename . $suffix . ".jpg";

echo $cmd . "<br />";

$output = system($cmd);

?>
********************************************

Strangely when I run the output in a shell manually, it works:

********************************************
$ convert /proj/ramwww/images/article_images/rachel.jpg -level 0,90%,1.1 -thumbnail '250x250>' \( +clone -background black -shadow 80x2+3+3 \) -repage +2+2 +swap -background white -mosaic /proj/ramwww/images/article_images/rachel_thm.jpg
********************************************

Has anyone experienced this problem when executing command line scripts?  Any ideas?

Thanks,
Eric
Patrick -

I thought I had commented the parenthesis using "\(" and "\)".  Am I missing something?

Effigy -

I've changed my code to pipe the output of STDERR to STDOUT (using "2>&1") and echo'ed the output of the command.  But still, nothing is returned as output:

*********************************************************
$cmd = "convert $filepath -level 0,90%,1.1 -thumbnail '" . $maxsize
. "x" . $maxsize . ">' \( +clone -background black -shadow 80x2+3+3 \)
-repage +2+2 +swap -background white -mosaic " . $basename . $suffix
. ".jpg 2>&1";

echo $cmd . "<br />";

$output = system($cmd);

echo "output is: " . $ouput . "<br />";
********************************************************

Again, I'm a bit of a unix newbie, so I might be missing something here, too.

Thanks guys!

Eric
SOLVED!

The command was:
convert /proj/ramwww/images/article_images/rachel.jpg -level 0,90%,1.1 -thumbnail '250x250>' \( +clone -background black -shadow 80x2+3+3 \) -repage +2+2 +swap -background white -mosaic /proj/ramwww/images/article_images/rachel_thm.jpg

when it should have been:
convert /proj/ramwww/images/article_images/rachel.jpg -level 0,90%,1.1 -thumbnail 250x250\> \( +clone -background black -shadow 80x2+3+3 \) -repage +2+2 +swap -background white -mosaic /proj/ramwww/images/article_images/rachel_thm.jpg

Some extraneous quotes and a missing backslash can make a world of difference.

Thanks to Patrick and Effigy for the help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.