[SOLVED] Problem with escaping quotes PHP

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
brianatlarge

[SOLVED] Problem with escaping quotes PHP

Post by brianatlarge »

For some reason, the following code works fine in the command line:

Code: Select all

/usr/local/bin/convert /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/car01.jpg -font Helvetica-Bold -pointsize 50 -draw "gravity center fill black text 1,12 'SOLD' fill red text 0,11 'SOLD' " sold.jpg
But in my PHP script, I've got this line:

Code: Select all

exec("/usr/local/bin/convert /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/car01.jpg -font Helvetica-Bold -pointsize 50 -draw \"gravity center fill black text 1,12 'SOLD' fill red text 0,11 'SOLD' \" sold.jpg");
And it doesn't go through. My error log has this:

Code: Select all

convert: unable to open image `sold.jpg':  @ error/blob.c/OpenBlob/2584.
[Mon Dec 06 17:39:52 2010] [error] [client 192.168.1.200] File does not exist: /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/sold.jpg, referer: http://kolamotors2/vehicles.php
[Mon Dec 06 17:39:52 2010] [error] [client 192.168.1.200] File does not exist: /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/sold.jpg, referer: http://kolamotors2/vehicles.php
[Mon Dec 06 17:39:54 2010] [error] [client 192.168.1.200] File does not exist: /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/sold.jpg, referer: http://kolamotors2/vehicles.php
[Mon Dec 06 17:39:54 2010] [error] [client 192.168.1.200] File does not exist: /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/sold.jpg, referer: http://kolamotors2/vehicles.php
The only difference I can see is that I'm escaping quotations. Is there a way to do this so it will work?
Last edited by brianatlarge on 2010-12-07T07:22:47-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problem with escaping quotes PHP

Post by anthony »

It isn't the command it is the environment.

PHP run from the web may not run in the same directory, or be able to write to the directory.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
brianatlarge

Re: Problem with escaping quotes PHP

Post by brianatlarge »

Fixed it. Had to change this:

Code: Select all

    exec("/usr/local/bin/convert /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/car01.jpg -font Helvetica-Bold -pointsize 50 -draw \"gravity center fill black text 1,12 'SOLD' fill red text 0,11 'SOLD' \" sold.jpg");
To this:

Code: Select all

    exec("/usr/local/bin/convert /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/car01.jpg -font Helvetica-Bold -pointsize 50 -draw \"gravity center fill black text 1,12 'SOLD' fill red text 0,11 'SOLD' \" /home/brian/Kola_Motors/html/images/gallery/2006AudiA6-069767/thumb/sold.jpg");
Post Reply