I'm drawing the text output from display-dhammapada to an existing image. The following CLI command works:
convert test.jpg
-pointsize 30
-draw "gravity northwest
fill black
text 120,200 '$( display-dhammapada)'"
result.png
...except when I receive a quote that has a contraction. Then the text input ends prematurely with an error such as:
convert: non-conforming drawing primitive definition `s' # error/draw.c/DrawImage/3182
which was an apostrophe s case.
If I reverse the quotes from " ' ' " to ' " " ' then I end up with the literal text $( display-dhammapada) on my image.
What is the best way to sanitize my input in this case?
You could sanitise your quote through sed like this:
convert -size 1000x1000 xc:red -pointsize 30 -draw "gravity northwest fill black text 120,200 '$(./display-dhammapada|sed "s/'/\\\'/g")'" result.png
display-dhammapada
#!/bin/bash
printf "There's one there!"
FYI:
It may be an idea to write a general purpose sanitiser script that you can maintain and modify. You could consider not allowing it to pass # as the first character which would make ImageMagick read a file and could permit attacks and you may not want to allow various other things through - e.g. trailing newlines, or semi-colons.
Related
I am generating a number of imagemagick commands to write out labels, one of the labels I need to write is the following:
[0]
whenever I get to the command with this label it does not work.
This is the specific command
convert -background white -fill black -font Arial -pointsize 24 label:[0] -rotate 90 16.png
when I run this in my Mac terminal I get the message
convert: no images defined `16.png' # error/convert.c/ConvertImageCommand/3282.
I have of course tried to escape with a backslash but neither
label:[0]
or
label:\[\0\]
or
label:[\0]
or
label:\[0\]
work, and each gives the same error. Any suggestions?
Try:
convert -pointsize 36 label:'\[0\]' image.png
The single quotes prevent the shell from seeing/interpreting the square brackets as a bracket expression and the backslashes prevent ImageMagick from believing they are part of an fx-like expression.
I'm trying to print pretty simple stuff
The double quotes "
The single quote '
The backslash \
And 2x backslashes \\
I'm using this command
convert -size 600x600 -gravity center -pointsize 30 caption:"The double quotes \"\nThe single quote \'\nThe backslash \\ \nAnd 2x backslashes \\\\" out.jpg
And getting this result:
The problem is that escaping backslashes is not working correctly
I've tried to run the command with single quotes instead of double likes this:
convert -size 600x600 -gravity center -pointsize 30 caption:'The double quot...
But then I do not know how to escape single quote '. I do know that is trivial but I do not have any other ideas.
I think you can do what you seek like this:
convert -size 600x600 -gravity center -pointsize 30 caption:'The double quotes \"\nThe single quote '"'"'\nThe backslash \\ \nAnd 2x backslashes \\\\' out.jpg
I'm trying to convert a text label into image using imagemagick's convert util following the guide at official page
I'm using the following command.
convert -background lightblue -pointsize 72 label:" spaces " label.gif
Although my text as leading whitespace, the output image has no space in the front. Spaces are getting trimmed. Trailing spaces have no issue though. I've tried the solution given at this SO question too in vain.
While I had typed this question and was waiting to post it, I figured out a way by guessing ;-)
The solution is simply to escape the first space with blackslash.
convert -background lightblue -pointsize 72 label:"\ spaces " spaces.gif
I am using imagemagick to create some simple graphics using the Dymo font. Here is an example:
convert -background White -fill DarkRed -font Dymo -pointsize 72 label:"DYMO FONT" -trim name.png
This command creates a file that looks like this:
I would like the red to fill all the way across, so that the image looks like a single label. I plan to use this on a page with a black background, which makes it look even worse.
I have played around with this for a while with no luck. Help would be appreciated.
Version: ImageMagick 6.9.2-7 Q16 x86_64 2015-12-06
O/S: Fedora 23
I don't know why it does that, but you can generate the text you want by replacing the space with a UTF non-breaking space and sending that to the stdin of convert and asking -label to read its text from the "file" called stdin:
printf "DYMO\xc2\xa0FONT" |
convert -background white -fill DarkRed -font DYMO -pointsize 72 label:#- result.png
Add -trim just before the output filename if you want the extraneous white space trimmed off from around the edges.
If you had more complicated text and didn't want to do that for all spaces, you could replace spaces using a short piece of Perl or sed to do it for you...
echo -n "Text with lots of spaces." | sed 's/ /\xC2\xA0/g' | convert -background white -fill DarkRed -font dymo -pointsize 72 label:#- -trim label.png
I'm generating CAPTCHAs for training data and I have a pretty good ImageMagick script going already.
However, one thing I really want is for individual letters of the word to be slightly rotated, see for example this reCAPTCHA:
Is there an easy (or hard) way to accomplish this effect?
I think you need this:
#!/bin/bash
word="theId"
for (( i=0 ; i<${#word} ; i++ )) ; do
rotation=$(((RANDOM%10)*4)) # Generate random rotation for each letter
convert -background none -virtual-pixel none -pointsize 72 label:"${word:i:1}" +distort SRT $rotation miff:-
done | convert -background none - +append result.png
Basically I am creating and rotating one letter at a time and writing them to a MIFF stream, one after the other, and at the end, I am using +append to join together everything I see on the input stream.
If you want to scrunch the letters closer together (TM) you can add -trim +repage just before miff:-