Imagemagick convert with font Helvetica - image

I am trying to create a text with this font : HelveticaNeueLTStd-Roman
The font is listed in my Imagick if I do this: identify -list font
...
Font: HelveticaNeueLTStd-Roman
family: HelveticaNeueLTStd-Roman
style: Normal
stretch: Normal
weight: 400
glyphs: c:\windows\fonts\helveticaneueltstd-roman_0.otf
...
My command looks like this:
convert -debug annotate -size 720x576 -background none -fill white -stroke white
-font HelveticaNeueLTStd-Roman -pointsize 22 90x25 -draw "text 160,420 'Test 1'"
-font HelveticaNeueLTStd-Roman -pointsize 22 50x25 -draw "text 310,420 'Text 2'"
-font HelveticaNeueLTStd-Roman -pointsize 22 115x25 -draw "text 425,420 'Text 3'" result.png
But I get following error (cmd):
convert -debug annotate -size 720x576 -background none -fill white -stroke white -font HelveticaNeueLTStd-Roman -pointsize 22 90x25 -draw "text 160,420 'Test 1'" -font HelveticaNeueLTStd-Roman -pointsize 22
50x25 -draw "text 310,420 'Text 2'" -font HelveticaNeueLTStd-Roman
-pointsize 22 115x25 -draw "text 425,420 'Text 3'" result.png
convert.exe: unable to open image `90x25': No such file or directory # error/blob.c/OpenBlob/2702.
convert.exe: no decode delegate for this image format `' # error/constitute.c/ReadImage/501.
convert.exe: unable to open image `50x25': No such file or directory # error/blob.c/OpenBlob/2702.
convert.exe: no decode delegate for this image format `' # error/constitute.c/ReadImage/501.
convert.exe: unable to open image `115x25': No such file or directory # error/blob.c/OpenBlob/2702.
convert.exe: no decode delegate for this image format `' # error/constitute.c/ReadImage/501.
convert.exe: no images defined `result.png' # error/convert.c/ConvertImageCommand/3252.
What I am doing wrong?

try this:
magick convert -size 720x576 xc:none -fill white -stroke white
-font Arial -pointsize 22 -draw "text 160,420 'Test 1'"
-font Arial -pointsize 22 -draw "text 310,420 'Text 2'"
-font Arial -pointsize 22 -draw "text 425,420 'Text 3'" result.png
I have changed Helvetica into Arial and used IMv7 syntax. Should be easy to adjust though.

The -pointsize setting only takes ONE parameter (the point-size), not TWO as you have.
Also, the -font and -pointsize are actually settings so there is no need to repeat them - they stay set until changed.

Related

Convert in bash pipe does not work as wanted

Not sure if this is convert problem or bash, since I have not seen similar issue in other bash scripts.
Core script as following. The $text is "( img,white30.png,0,0,30,30 img,white30.png,560,320,30,30 3℃ img,iconall.png,0,0,24,24 img,iconall.png,200,0,24,24 '<3级' )". The result is supposed to be a $color-ed roundrectangle, with "image image 3℃ image image <3级" (no space) on it.
If I manually execute the logic, all fine. But when I run the script with -x, I got a confusing sequence of commands (see the last part of the question) and result picture (The 3℃ part is just blank with seems-about-right place held).
convert -size "${w}x${h}" canvas:transparent -fill "${color}" -draw "roundrectangle 0,0,${w},${h},15,15" "PNG32:${iPic}"
local x=0
for i in "${text[#]}"; do
if [[ "${i}" == img,* ]]; then
IFS=, read -r img filename x1 y1 w1 h1 <<< "${i}"
convert "${filename}" -crop "${w1}x${h1}+${x1}+${y1}" - |
convert "${iPic}" - -gravity northwest -geometry "+${x}+$(( (h - h1) / 2 ))" -composite "${oPic}"
else
local wxh
wxh="$(textSize "${i}")"
w1="$(cut -dx -f1 <<< "${wxh}")"
convert -size "${w}x${h}" canvas:black -fill white -draw "roundrectangle 0,0,${w},${h},15,15" PNG32:- |
convert - canvas:white -fill black -pointsize 40 -font Noto-Sans-Mono-CJK-SC-Regular -gravity northwest -annotate "+${x}+0" "${i}" PNG32:- |
convert "${iPic}" - -alpha Off -compose CopyOpacity -composite "${oPic}"
fi
x=$(( x + w1 ))
cp -f "${oPic}" "${iPic}"
done
convert "${src}" "${oPic}" -gravity "${gravity}" -geometry "${position}" -composite "${dest}"
bash -x output (only calls to convert):
+++ convert -debug annotate xc: -font Noto-Sans-Mono-CJK-SC-Regular -pointsize 40 -annotate 0 3℃ null:
+++ convert -debug annotate xc: -font Noto-Sans-Mono-CJK-SC-Regular -pointsize 40 -annotate 0 '<3级' null:
+ convert -size 254x59 canvas:transparent -fill '#8fa6bc' -draw 'roundrectangle 0,0,254,59,15,15' PNG32:/tmp/tmp.zBBu2pNx1h
+ convert white30.png -crop 30x30+0+0 -
+ convert /tmp/tmp.zBBu2pNx1h - -gravity northwest -geometry +0+14 -composite /tmp/tmp.lPXXH4jNsW
+ convert white30.png -crop 30x30+560+320 -
+ convert /tmp/tmp.zBBu2pNx1h - -gravity northwest -geometry +30+14 -composite /tmp/tmp.lPXXH4jNsW
+++ convert -debug annotate xc: -font Noto-Sans-Mono-CJK-SC-Regular -pointsize 40 -annotate 0 3℃ null:
+ convert -size 254x59 canvas:black -fill white -draw 'roundrectangle 0,0,254,59,15,15' PNG32:-
+ convert - canvas:white -fill black -pointsize 40 -font Noto-Sans-Mono-CJK-SC-Regular -gravity northwest -annotate +60+0 3℃ PNG32:-
+ convert /tmp/tmp.zBBu2pNx1h - -alpha Off -compose CopyOpacity -composite /tmp/tmp.lPXXH4jNsW
+ convert iconall.png -crop 24x24+0+0 -
+ convert /tmp/tmp.zBBu2pNx1h - -gravity northwest -geometry +122+17 -composite /tmp/tmp.lPXXH4jNsW
+ convert iconall.png -crop 24x24+200+0 -
+ convert /tmp/tmp.zBBu2pNx1h - -gravity northwest -geometry +146+17 -composite /tmp/tmp.lPXXH4jNsW
+++ convert -debug annotate xc: -font Noto-Sans-Mono-CJK-SC-Regular -pointsize 40 -annotate 0 '<3级' null:
+ convert -size 254x59 canvas:black -fill white -draw 'roundrectangle 0,0,254,59,15,15' PNG32:-
+ convert - canvas:white -fill black -pointsize 40 -font Noto-Sans-Mono-CJK-SC-Regular -gravity northwest -annotate +170+0 '<3级' PNG32:-
+ convert /tmp/tmp.zBBu2pNx1h - -alpha Off -compose CopyOpacity -composite /tmp/tmp.lPXXH4jNsW
+ convert - /tmp/tmp.lPXXH4jNsW -gravity southeast -geometry +0+300 -composite -

Convert .otf font into a .gif image of all glyphs

How can I convert a .otf font file into a .gif image, where each glyph within the font occupies a single frame in the gif?
I have seen imagemagick used to convert glyphs into pngs,
convert -background none -fill black -font font.otf -pointsize 300 label:"Z" z.png
Is this extendable for what I am after?
Or do I need to use a different method?
(Also note that the above command doesn't work properly for me, the font I am using, tangwar-annatar, has some glyphs that were cut off by the edges of the png generated by the above command)
I'm on a mac with access to pretty much everything, so would accept any solution in any language as long as it works for me.
Updated Again
Ok, I have seen your font and the characters seem to extend beyond the expected sizes. I think all you need to do is use a bigger canvas:
#!/bin/bash
{
for c in {a..z} {A..Z} {0..9}; do
convert xc:none[1000x1000] -background none -fill black -font tengwar.otf -pointsize 300 \
-gravity center -annotate 0 "$c" miff:-
done
# Do any problematic characters as an afterthought, e.g. semi-colon, and exclamation
convert xc:none[1000x1000] -background none -fill black -font tengwar.otf -pointsize 300 \
-gravity center -annotate 0 ";" miff:-
convert xc:none[1000x1000] -background none -fill black -font tengwar.otf -pointsize 300 \
-gravity center -annotate 0 "!" miff:-
} | convert -dispose background -delay 20 miff:- anim.gif
Updated Answer
You may get on better with -annotate on a fixed background as below. I have also added how to deal with problematic characters in this example - you can do the same in the other example too:
#!/bin/bash
{
for c in {a..z} {A..Z} {0..9}; do
convert xc:none[350x350] -background none -fill black -font arial -pointsize 300 \
-gravity center -annotate 0 "$c" miff:-
done
# Do any problematic characters as an afterthought, e.g. semi-colon, and exclamation
convert xc:none[350x350] -background none -fill black -font arial -pointsize 300 \
-gravity center -annotate 0 ";" miff:-
convert xc:none[350x350] -background none -fill black -font arial -pointsize 300 \
-gravity center -annotate 0 "!" miff:-
} | convert -dispose background -delay 20 miff:- anim.gif
Original Answer
You can do something like this:
#!/bin/bash
for c in {a..z} {A..Z} {0..9}; do
convert -background none -fill black -font arial -pointsize 300 \
label:"$c" -gravity center -extent 350x350 miff:-
done | convert -dispose background -delay 80 miff:- anim.gif

Imagemagick change label font and squash

Is it possible to change the font of a label?
I have following command:
> convert -background none -bordercolor none -gravity west -fill white
> img1.png label:"1" -border 0x5 +swap -append -font "Helvetica-LT-55-Roman" label:"Chapter 1" -border
> 0x5 -append -write miff:- +delete img2.png label:"2" -border 0x5 +swap
> -append label:"Chapter 2" -border 0x5 -append -write miff:- +delete img3.png label:"3" -border 0x5 +swap -append label:"Chapter 3" -border
> 0x5 -append -write miff:- +delete img4.png label:"4" -border 0x5 +swap
> -append label:"Chapter 4" -border 0x5 -append -write miff:- +delete img5.png label:"5" -border 0x5 +swap -append label:"Chapter 5" -border
> 0x5 -append miff:- | montage -set label "" miff:- -tile 3x2 -geometry
> +15-10 -background none result.png
which creates me an image with 5 image, each image has a text above and under.
If I:
convert -list font
it does show me the font I want to use.
Thus is there a way to squash the label(text) width?
Please try to make your examples simpler!
Do you want to know how to change the font of a label? Or do you want to know how to crop a label's width?
If you list your fonts like this:
identify -list font
Output
Font: Palatino-Bold
family: Palatino
style: Normal
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/p052004l.pfb
Font: Palatino-BoldItalic
family: Palatino
style: Italic
stretch: Normal
weight: 700
glyphs: /usr/local/share/ghostscript/fonts/p052024l.pfb
Font: Palatino-Italic
family: Palatino
style: Italic
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/p052023l.pfb
Font: Palatino-Roman
family: Palatino
style: Normal
stretch: Normal
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/p052003l.pfb
You can then create a label with a Palatino-Italic font and trim it like this:
convert -undercolor yellow -pointsize 36 -font Palatino-Italic label:"Palatino-Italic" -trim result.png
What does "squash" mean? Please define or provide an example of such a process.
If you mean distort the image to have a smaller width, then you can use -resize to do so. For example to reduce the width by half and keep the height the same, use -resize 50x100%

Crop image and extend with blurred background

I really like how hangtime.com crops their images to fit and then add a blurred background to them as here.
Does someone know how this is done?
here's an ImageMagick command line that should do something similar:
convert ( -blur 0x50 -gravity center -resize 640x480^ -crop 480x480+0+0 -resize 640x480! a.jpg ) -gravity east ( -background none -size 480x320 gradient:black-none -rotate 270 ) -composite -gravity west ( -background none -size 480x320 gradient:black-none -rotate 90 ) -composite -gravity center ( a.jpg -resize 640x480^ -crop 470x480+0+0 ) -composite output.jpg

Connected-component labeling with ImageMagick

Is it possible to perform a connected-component labeling on a image with ImageMagick?
Connected-component labeling in Wikipedia
Yes, it is now possible with ImageMagick 6.8.9-10 and newer, see here.
So, if we start with this image:
we can get the components labelled and also the bounding boxes, centroids and other statistics for each blob or component like this:
convert input.png \
-colorspace gray -negate -threshold 10% \
-define connected-components:verbose=true \
-define connected-components:area-threshold=100 \
-connected-components 8 -auto-level output.png
Objects (id: bounding-box centroid area mean-color):
0: 600x600+0+0 296.9,299.6 260033 srgb(0,0,0)
2: 467x345+70+211 350.1,398.1 53563 srgb(255,255,255)
1: 422x105+56+81 266.5,133.0 34814 srgb(255,255,255)
4: 105x90+112+310 164.0,354.5 9450 srgb(255,255,255)
3: 178x73+393+246 481.5,282.0 2140 srgb(255,255,255)
You can then draw in the bounding box like this:
convert output.png -fill none -stroke red \
-draw "rectangle 70,211 537,556" \
-draw "rectangle 56,81 478,186" \
-draw "rectangle 112,310 217,400" \
-draw "rectangle 393,246 571,319" \
x.png

Resources