I need to annotate some label/text containing greek letters on a figure using convert from imagemagick on linux.
What is the best option?
Trivial choices such as:
ii=1
label="α β $ii"
convert in.png -fill black -annotate "$label" out.png
won't work.
I am not familiar with font coding options.
One way that works for me in ImageMagick 6.9.9.23 Mac OSX Sierra is to use a Greek font. (The symbol font also works)
ii=1
label="a b $ii"
convert logo: -font GreekMathSymbols -pointsize 64 -gravity center -fill red -annotate +0+0 "$label" out.png
Alternately, use a UTF-8 compatible text editor and type your text using a font that supports those characters. For example I put your alpha beta one characters into a text file using the same GreekMathSymbols font.
Then
convert logo: -font GreekMathSymbols -pointsize 64 -gravity center -fill red -annotate +0+0 "#greek.txt" out2.png
See also http://www.imagemagick.org/Usage/text/#unicode
Related
I have this code in ImageMagick, it works except for changing the font. I tried all kinds of options, I don't understand what I could do to change the font to the font I want.
Besides that, how can I give opacity to ``-undercolor "#E70E0E"```?
magick convert 13.jpg -fill white -undercolor "#E70E0E" -gravity Center -font "Comic Sans MS" -pointsize "75" -annotate +0+5 "Title-text" -gravity Center -pointsize "25" -font "Calibri Light" -annotate +0+100 "SubTitle-Text" -crop 1920x1080+0+0 -scale 1920x1080+0+0 picture.jpg
thank you so much
Possibly missing dashes in the font names (Calibri-Light).
You can list the fonts known to IM using magick identify -list font.
I can do this to draw a red rectangle on an image:
convert original.png -fill red -draw "rectangle 10,20 150,40" result.png
The 150,40 is the right bottom coordinate. However if I use the %[fx:...] operator in there, like so:
convert original.png -fill red -draw "rectangle 10,20 %[fx:w-30],40" result.png
The %[fx:w-30] is supposed to evalute to the image's width minus 30.
However I'm getting an error:
convert: non-conforming drawing primitive definition `rectangle' # error/draw.c/DrawImage/4227.
I have also tried single quotes (') instead of double (") but that made no difference.
My imagemagick version is 7.0.7-36.
What am I doing wrong? What's the correct way of using the %[fx:...] operator in the above example?
Thanks to #GeeMack the solution is: use magick instead of convert, so it becomes:
magick original.png -fill red -draw "rectangle 10,20 %[fx:w-30],40" result.png
If you're still on ImageMagick 6, you can use the identify command to output a formatted string and then use that in the convert command. Using shell syntax, this can be expressed as follows:
convert original.png -fill red -draw "$(identify -format 'rectangle 10,20 %[fx:w-30],40' original.png)" result.png
I use Ubuntu 14.0.4. I want to use a file with UTF8 by a command of ImageMagick. Here you can see:
If the UTF-8 text you wanting to draw has already been generated you
can read it directly from a file using '#filename'.For example here I
create a Chinese label from a UTF-8 encoded Chinese text file (without
a final newline in the file).
convert -background lightblue -fill blue -pointsize 48 \
-font ZenKaiUni label:#chinese_words.utf8 label_utf8.gif
Now I test a command that is look like above command for a text file with name label1.txt which it's content is a Persian word:
سلام
Command is:
convert -background lightblue -fill blue -pointsize 48 label:#label1.txt label_utf8.png
But I got this image:
You can see ? characters instead of desired ones. How can I solve this problem?
Firstly, you need to specify the font for ImageMagick to use, so you want something like:
convert -background lightblue -fill blue -pointsize 48 -font XYZ ...
In order to make sure that your selected font is known to ImageMagick, you need to look in the list of known fonts:
identify -list font
or, more specifically in your case:
identify -list font | grep -i Kacst
If the font is listed, use that name. If not listed, refer to this answer.
I need to count pixels in an image that are not background color.
I am calling this from PHP (it's from ImageMagick):
gm convert test.png -fill black +opaque "rgb(255,255,255)" -fill white -opaque "rgb(255,255,255)" -print "pixels = %[fx:w*h*mean]\n"
But it does not give any result, nothing.
I tried using histogram instead:
gm convert test.png -define histogram:unique-colors=true -format %c histogram:info.txt
That works, but gives values for every color and more details, I just need a single number please.
You have got a couple of issues here. You seem to be trying to mix GraphicsMagick with ImageMagick when they are not the same thing.
Firstly, GraphicsMagick does not have the +opaque operator that ImageMagick has.
Secondly, it doesn't have the -fx operator that ImageMagick has for doing maths.
I would suggest you move to, the more powerful, ImageMagick. Then it will work as you expect:
# Create a test image
convert -size 200x200 xc:black xc:white xc:red +append image.png
# Count the white pixels
convert image.png -fill black +opaque "rgb(255,255,255)" -print "pixels = %[fx:w*h*mean]\n" nul:
pixels = 40000
If you really, really must do it with GraphicsMagick, I can only suggest the following - which is heavily based on #GlennRanders-Pehrson answer here:
gm convert image.png +matte -matte -transparent white -operator matte negate 1 result.png
gm identify -verbose result.png | grep -EA5 "Opacity:|Geometry:" | grep -E "Mean|Geometry"
Geometry: 600x200
Mean: 43690.00 (0.6667)
Mean: 43690.00 (0.6667)
And your answer will be:
600 * 200 * (1 - 0.667)
I want to convert given text, say TEST, to image in different font and style.
I am using Imagemagick's convert command
convert -pointsize 120 -font Courier label:'TEST' test.png
But when I am using -style in the same, it is not changing into different style like Normal, Bold, Italic.
Please suggest how to get all 3 style.
I think -style (e.g. Italic) and -weight (e.g. Bold) only work for certain fonts like postscript ones (unable to quote you a definitive source though).
What I use is fonts like Courier-New-Bold, Courier-New-Italic, Courier-New-Bold-Italic.
e.g.:
convert -pointsize 120 -font Courier label:'TEST' test.png
convert -pointsize 120 -font Courier-New-Bold label:'TEST' testbold.png
convert -pointsize 120 -font Courier-New-Italic label:'TEST' testitalic.png
convert -pointsize 120 -font Courier-New-Bold-Italic label:'TEST' testbolditalic.png
Most fonts have the -Bold, -Italic, and -Bold-Italic versions.
To see what fonts you can use, do convert -list font (or convert -list type if your ImageMagick is older). I do convert -list font | grep Font: to get a condensed list of just font names.