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
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'd like to draw a text onto an image in a way like this:
convert -quality 100 -font Oswald-Regular -pointsize 515 -fill black -draw "text 1339.0,1099 'some text'" /tmp/ascript.png /tmp/ascript.png
and I need to know the dimensions of the text with the above parameters (size, font, text). How can I get that?
I tried something like this:
convert -size 5000x1500 xc:lightblue -font Oswald-Regular -pointsize 515 -fill none -undercolor white -annotate +20+100 'some text' -trim info:
but it's giving false result:
xc:lightblue XC 1834x250 5000x1500+19+0 16-bit sRGB 0.010u 0:00.000
.
What is the proper way (or a working way) to get the dimension of a drawn image based on this 3 parameters (font, size, text)?
I'm not strictly binded to ImageMagick, it can be any command line tool for the Linux shell, however, the text will be drawn by convert.
There are a couple simple ways to get the dimensions using ImageMagick with commands like this...
convert -size 5000x1500 xc:lightblue -font Oswald-Regular -pointsize 515 \
-fill none -undercolor white -annotate +20+100 'some text' \
-format "%[#]\n" info:
That uses the FX escape "%#" as the formatting string for the "info:" output. It will show IM's calculation of the after-trim width, height, horizontal offset, and vertical offset like "WxH+X+Y".
This similar command just gives the width and height of the trimmed text...
convert -size 5000x1500 xc:lightblue -font Oswald-Regular -pointsize 515 \
-fill none -undercolor white -annotate +20+100 'some text' \
-trim +repage -format "%[w]x%[h]\n" info:
That will trim the text, reset the paging geometry with "+repage", then output a string showing "WxH".
––– Edited to Add –––
I tried your image with_text.png with these commands. The output immediately follows each command...
convert with_text.png -format "%[#]\n" info:
1807x389+512+115
convert with_text.png -trim +repage -format "%[w]x%[h]\n" info:
1807x389
Those were tested with IMv6.8.9-9 on ubuntu bash on Windows 10. If you use that actual image and those commands, I'm not sure why you would get different results.
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.
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 have written the following script which uses the ImageMagick* convert utility to append axis labels to an existing image.
LEFT_="l -30,0 +2,+2 -6,-2 +6,-2 -2,+2 z"
RIGHT_="l 30,0 -2,+2 +6,-2 -6,-2 +2,+2 z"
convert -size 240x160 pattern:SMALLFISHSCALES \
-pointsize 16 -fill black -background white \
-gravity SouthEast -splice 0x20 \
-draw "translate 40,0 text 0,0 'Time' stroke red path 'm 5,2 $RIGHT_'" \
-gravity NorthWest -splice 20x0 \
-draw "rotate +90 translate 40,-10 text 0,0 'Value' path 'm -5,2 $LEFT_'" \
example.png
Which produces the following image:
This is almost exactly what I am after, except that the red arrow is out of place. I expected the red arrow to appear next to the Time label, since its start point is specified as a relative position in the same draw command. Unfortunately, it looks like the -gravity option is affecting the text primitive, but not the path primitive.
Is there a way to reference the SouthEast corner, or the Time text label when specifying the start position of the red arrow? I can't use absolute coordinates, because the size of the image varies.
*ImageMagick 6.7.8-9 on CentOS 7
Updated Answer
Maybe you can make Unicode text arrows like this then they will be affected by gravity...
perl -e 'binmode(STDOUT,":utf8"); print "Time ... \x{2192}\x{2191}";'|
convert -font TimesNewRoman -pointsize 36 label:#- arrows.png
Depending on your OS, the following may do as a replacement for the Perl above...
printf "%b" "\u2192" | convert ...
Original Answer
I am not at all familiar with paths, but I can suggest a way to achieve what you want that doesn't use gravity at all, and maybe that will help.
Rather than use -splice, you can clone your original image and crop it to the size you planned to splice on, and then -append the strips that label the axes. It is easier to show you the command than explain it!
convert -size 240x160 pattern:SMALLFISHSCALES \
\( +clone -crop x20+0+0 -fill blue -colorize 100% \) \
-append \
\( +clone -crop 20x+0+0 -fill red -colorize 100% \) \
+swap +append result.png
I have filled the x-axis blue, but remove that and add whatever labelling and arrows you need, and I filled the y-axis red, but likewise remove that and add labelling and arrows - rotating as necessary.
Two tricky things to note...
-append will append the second image below the first
+append will append the second image to the right of the first, so I +swap beforehand to put it on the left side.