I have a php page with a form where a user can enter text for a list. These fields insert into a MySQL database using the mysqli_real_escape_string method. I've checked the database and it shows up correctly as: "eric's test" so I know it is inserted into the DB with the apostrophe.
Then I do a SELECT statement and pull the data (in a loop to build a list of text) and use label: to create an image.
start loop code....
$bullettitle .= $row_bullets_element['bullettitle']."\n"; <---- I added the \n to cause line breaks for a list effect.
end loop code....
The below only works if the $bullettitle doesn't have an apostrophe such as the string: eric's test
exec("convert -interline-spacing {$previewbulletsfontspacing} -background none -size {$previewbulletswidth}x -fill '{$fontcolorbullets}' -font Arial -pointsize {$previewbulletsfontsize} label:'{$bullettitle}' {$previewbulletsfilenamepath}");
I've tried backslashing like this: eric\'s test but it doesn't even render. How does this work? I've tried this for several days and no test comes thru. Thank you.
Apostrophe not working with ImageMagick
-
- Posts: 2
- Joined: 2014-06-24T13:10:31-07:00
- Authentication code: 6789
Re: Apostrophe not working with ImageMagick
Out of interest in this case you only need the { and } in your code for -size {$previewbulletswidth}x
What does $bullettitle contain if you echo it out; does eric's test display as it should?
The first thing I would try is changing label:'{$bullettitle}' to label:\"$bullettitle\"
I also write my code like this so you can echo $cmd out to confirm what you are using
What does $bullettitle contain if you echo it out; does eric's test display as it should?
The first thing I would try is changing label:'{$bullettitle}' to label:\"$bullettitle\"
I also write my code like this so you can echo $cmd out to confirm what you are using
Code: Select all
$cmd = " -size {$previewbulletswidth}x xc:none -interline-spacing $previewbulletsfontspacing -fill $fontcolorbullets -font Arial -pointsize $previewbulletsfontsize label:\"$bullettitle\" $previewbulletsfilenamepath";
// echo $cmd.'<br>';
exec("convert $cmd" );
-
- Posts: 2
- Joined: 2014-06-24T13:10:31-07:00
- Authentication code: 6789
Re: Apostrophe not working with ImageMagick
Your advice here fixed it!!:
"The first thing I would try is changing label:'{$bullettitle}' to label:\"$bullettitle\""
I can't begin to tell you how many days I've tried to debug this before giving up and posting. Any advice or suggestions as to why this fixed it? Simply adding double quotes and removing the curly braces?
I am so thankful for your help - I may just hit my deadline afterall. My family thanks you as well!
"The first thing I would try is changing label:'{$bullettitle}' to label:\"$bullettitle\""
I can't begin to tell you how many days I've tried to debug this before giving up and posting. Any advice or suggestions as to why this fixed it? Simply adding double quotes and removing the curly braces?
I am so thankful for your help - I may just hit my deadline afterall. My family thanks you as well!
Re: Apostrophe not working with ImageMagick
I do not think removing the curly brackets had any effect and I assume the ' in eric's was closing the first ' so you had eric. But it is strange you did not have an error as you would then have had a stray ' in your command.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Apostrophe not working with ImageMagick
The OP says it didn't work when the label contained an apostrophe (ie a single-quote). I expect Bonzo is correct, that the quote inside the string was closing the open-quote. At the command line, escaping the embedded quote would work, eg (in Windows, which uses double-quotes):
PHP has an extra layer of translation, so perhaps the escape character was being removed too early. Perhaps doubling the escape would work?
Code: Select all
convert -size 100x100 label:"Eric\"s test" t.png
snibgo's IM pages: im.snibgo.com