Apostrophe in filename giving inconsistent results

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
SirXaph

Apostrophe in filename giving inconsistent results

Post by SirXaph »

Hi, I'm new :)
I came to start using ImageMagick because my host seems to kill php scripts that use too much memory, and a gd imagecreatefromjpeg with an 8 megapixel file was well above the limits they'd set.
I've had fantastic results with ImageMagick so far but am having some rather odd behaviour in the script I'm writing and figured i'd share..

Basically this part of code is meant to do a very similar thing as the polaroid function. (I actually was nearly finished writing it before I even realised the polaroid function existed... then I found that the version of imagick my host has installed doesn't have the function available anyway.)
Here's the pertinent code:

Code: Select all

$command = "convert " . $src . " -thumbnail " . $thumbmaxwidth . "x" . $thumbmaxheight . " -mattecolor \"#" . $imgbordercol . "\" -background \"#" . $imgbordercol . "\" -gravity South -splice 0x19 -annotate 0x0 '" . $fn . "' -frame 3x3+2+0 -matte -background none -rotate 90 -wave " . $amplitude . "x" . $wavelength . " -rotate -90 -rotate " . $rotateamt . " \( +clone -background gray75  -shadow 60x2+3+3 \) +swap -background none -mosaic -quality " . $thumbqual . " " . $dest;
exec($command);
$src has had escapeshellarg() run on it to ensure it should be safe to pass to ImageMagick.

The result: Image

So far so good.

The problem occurs when the filename has an apostrophe (') in it (eg Image )

Yet oddly the normal resize function works fine, with the same arguments:
http://antarctica.go-forth.co.uk/p2/res ... ls0016.jpg

code for that:

Code: Select all

$command = "convert " . $src . " -resize " . $maxwidth . "x" . $maxheight . "\> -fill white  -undercolor '#00000080'  -gravity South -annotate +0+5 ' " . $wmarktext . " ' -quality " . $resizequal . " " . $dest;
exec($command);
So.. my thoughts are that It shouldn't really be an issue with the $src variable (because otherwise the normal resize function would fail too)... but I have no real idea why a filename with an apostrophe would be fine with one convert command and not with the other. :?

Thoughts?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Apostrophe in filename giving inconsistent results

Post by Bonzo »

I would write the code slightly differently and do away with the ' It may not have any effect but what does this do ?

Code: Select all

// I am confused about the escapes rquired for the border colour so I did this ! There is a better way of writting this but I can not think what it is off hand.
$imgbordercol = "#".$imgbordercol";

$command = "$src -thumbnail {$thumbmaxwidth}x{$thumbmaxheight} -mattecolor  \"$imgbordercol\" ".
" -background \"$imgbordercol\" -gravity South -splice 0x19 -annotate 0x0 \" $fn \" -frame 3x3+2+0 ".
" -matte -background none -rotate 90 -wave {$amplitude}x{$wavelength} -rotate -90 -rotate $rotateamt ".
" \( +clone -background gray75  -shadow 60x2+3+3 \) +swap -background none -mosaic -quality $thumbqual ";

exec("convert $command $dest");
You can try adding some error reporting:

Code: Select all

$array=array();
echo "<pre>";
exec("convert $command $dest 2>&1", $array); 
echo "<br>".print_r($array); 
echo "</pre>";
SirXaph

Re: Apostrophe in filename giving inconsistent results

Post by SirXaph »

Aha, thanks replacing ' with /" in my code seems to have solved it!
I did try to see if the error reporting came back with anything useful, but just got an empty array back.
Post Reply