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.
Related
I want to simplify my Christmas card making process. I have already built a frame with some text, and I wanted to personalize each card with the recipients name by using imagemagick and some bash power. But so far I'm failing bad :(
This is what I tried at first:
for i in names.txt;
do convert -font Akaya-Telivigala-Regular -fill black -stroke black -strokewidth 1\
-pointsize 190 -draw 'text 640,730 $i' chrisFrame.svg -resize 70%\
greetings_$i.jpg;
done
But it fails with convert-im6.q16: non-conforming drawing primitive definition i' # error/draw.c/RenderMVGContent/4300.`.
Seeing that imagemagick was trying to use $i as a primitive, I tried to enclose it in double quotes, as I would do if I was passing the names by hand:
for i in names.txt;
do convert -font Akaya-Telivigala-Regular -fill black -stroke black -strokewidth 1\
-pointsize 190 -draw 'text 640,730 "$i"' chrisFrame.svg -resize 70%\
greetings_$i.jpg;
done
Of course it generated a beautiful file named greetings_names.txt.jpg with $i instead of the name.
The content of the names.txt file is nothing else than
John,
Jane,
What am I doing wrong and how can I make it work?
With the gracious help of #GeeMack and after correcting an error in the call of the for loop, the solution is this:
for i in `cat names.txt`;
do convert -font Akaya-Telivigala-Regular -fill black -stroke black\
-strokewidth 1 -pointsize 190 -draw "text 640,730 '$i'"\
chrisFrame.svg -resize 70% greeting_$i.jpg;
done
Effectively, inverting the single and double quotes made the trick.
Please notice that it was necessary to change also the line
for i in names.txt
for
for i in `cat names.txt`
EDIT TO ADD:
After #Jetchisel comment regarding why one should not use for to read lines out of a file, the correct code will be:
while read i
do convert -font Akaya-Telivigala-Regular -fill black\
-stroke black -strokewidth 1 -pointsize 190
-draw "text 640,730 '$i'" chrisFrame.svg\
-resize 70% greetings_$i.jpg;
done < names.txt
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 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
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)