Escape [0] in ImageMagick label - imagemagick

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.

Related

How to print backslash with ImageMagick convert caption feature?

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

How can I merge or convert multiple ImageMagick command into one single command

a) I have multiple ImageMagick commands and I need to convert those multiple commands into one. I tried it by putting all the parameters in single command, but somehow it was not working and I had to discard it.
magick -density 300 cheque25.jpg -depth 8 -strip -background white -alpha off cheque25.png
magick convert cheque25.png -resize 150% res_cheque25.png
magick convert -brightness-contrast 10x30 res_cheque25.png b_res_cheque25.png
magick convert b_res_cheque25.png -threshold 45% bin_res_cheque25.png
b) Also, is there any chance that merged commands will give any different output than multiple single command?
Your ImageMagick syntax is not correct in several ways. In ImageMagick 7, you replace convert with magick. Also your input should come right after magick. ImageMagick 6 is forgiving of syntax, but ImageMagick 7 is not. See http://imagemagick.org/script/porting.php#cli
Try the following:
magick cheque25.jpg -depth 8 -strip -alpha off -background white -resize 150% -brightness-contrast 10x30 -threshold 45% -density 300 bin_res_cheque25.png
If that does not work, then provide a link to your input image, so others can test your commands and verify against mine.
The combined commands should give the same as a properly formatted set of commands, provided no syntax errors are present and settings are reset where needed and parenthesis processing is properly used when and where needed. I make no guarantees, since your set of commands is not using proper syntax.

Escaping imagemagick text input with apostrophes

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.

convert text with leading space to image using imagemagick

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

IMAGEMAGICK: Filling when label contains blanks

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

Resources