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
Related
I've been using Fiji's FFT bandpass filter with great success, but I'd like to do this in the command line with ImageMagick. I see that ImageMagick has FFT filters and they documentation includes low-pass and high-pass filters, but can I perform a bandpass filter?
The bandpass filter settings from Fiji that seem to work well for me:
(With apologies that my filter and FFT knowledge is... really bad, so maybe this is easily accomplished if I knew what to chain together, etc...)
A band pass filter similar to the low pass one you show in your link would be a white ring on a black background for square images. The inner and outer radii of the ring determine the frequencies that would be passed. In ImageMagick you can do that as follows:
Input:
Create ring image:
convert lena-1.png -fill black -colorize 100 \
-fill white -draw "translate 64,64 circle 0,0 0,50" \
-fill black -draw "translate 64,64 circle 0,0 0,20" \
-alpha off -blur 0x1 \
ring.png
Do FFT processing with stretch to full dynamic range:
convert lena-1.png -fft \
\( -clone 0 ring.png -compose multiply -composite \) \
-swap 0 +delete -ift -auto-level \
lena_bp.png
Alternate processing with gain of 10x:
convert lena-1.png -fft \
\( -clone 0 ring.png -compose multiply -composite \) \
-swap 0 +delete -ift -evaluate multiply 10 \
lena_bp.png
As I do not know what they have coded in ImageJ or Fiji and you showed no output, I can only guess that what might be equivalent would be to have inner and outer radii at 3 and 40 pixels from the center. Also I have added again a gain of 10x in dynamic range to make it more visible:
convert lena-1.png -fill black -colorize 100 \
-fill white -draw "translate 64,64 circle 0,0 0,40" \
-fill black -draw "translate 64,64 circle 0,0 0,3" \
-alpha off -blur 0x1 \
ring.png
convert lena-1.png -fft \
\( -clone 0 ring.png -compose multiply -composite \) \
-swap 0 +delete -ift -evaluate multiply 10 \
lena_bp.png
Note that I blurred the ring slightly to reduce "ringing" artifacts. (See https://en.wikipedia.org/wiki/Ringing_artifacts). Many low pass, high pass and band pass filters have stronger/longer tapering similar to increasing the blur. There are specially designed tapers, such as Butterworth. (see https://en.wikipedia.org/wiki/Butterworth_filter)
I have an expanded version of the FFT documentation from ImageMagick at http://www.fmwconcepts.com/imagemagick/fourier_transforms/fourier.html (Note some of the Jinc filtering is a bit outdated. Since I wrote that, Imagemagick implemented the Jinc function within -fx)
Here is a small set of commands to do it all in Unix syntax. Remove the +write ring.png if you do not want it to be created. This code is limited to square images.
ImageMagick 6:
inner=3
outer=40
infile="lena-1.png"
cent=`convert "$infile" -format "%[fx:floor((w-1)/2)]" info:`
inname=`convert "$infile" -format "%t" info:`
suffix=`convert "$infile" -format "%e" info:`
convert "$infile" \
\( +clone -fill black -colorize 100 \
-fill white -draw "translate $cent,$cent circle 0,0 0,$outer" \
-fill black -draw "translate $cent,$cent circle 0,0 0,$inner" \
-alpha off -blur 0x1 +write ring.png \
-write mpr:bpass +delete \) \
-fft \( -clone 0 mpr:bpass -compose multiply -composite \) \
-swap 0 +delete -ift -evaluate multiply 10 \
${inname}_bandpass_${inner}_${outer}.$suffix
ImageMagick 7 (only one command line):
inner=3
outer=40
infile="lena-1.png" \
magick "$infile" \
-set option:cent "%[fx:floor((w-1)/2)]" \
-set filename:fn "%t_bandpass_${inner}_${outer}.%e" \
\( +clone -fill black -colorize 100 \
-fill white -draw "translate "%[cent],%[cent]" circle 0,0 0,$outer" \
-fill black -draw "translate "%[cent],%[cent]" circle 0,0 0,$inner" \
-alpha off -blur 0x1 +write ring.png \
-write mpr:bpass +delete \) \
-fft \( -clone 0 mpr:bpass -compose multiply -composite \) \
-swap 0 +delete -ift -evaluate multiply 10 \
"%[filename:fn]"
If you mean band enhanced (band boost) and not band pass, then you add the result back with the original (-compose plus -composite). In ImageMagick 6, that would be:
inner=3
outer=40
infile="lena-1.png"
cent=`convert "$infile" -format "%[fx:floor((w-1)/2)]" info:`
inname=`convert "$infile" -format "%t" info:`
suffix=`convert "$infile" -format "%e" info:`
convert "$infile" \
\( +clone -fill black -colorize 100 \
-fill white -draw "translate $cent,$cent circle 0,0 0,$outer" \
-fill black -draw "translate $cent,$cent circle 0,0 0,$inner" \
-alpha off -blur 0x1 +write ring.png \
-write mpr:bpass +delete \) \
-fft \( -clone 0 mpr:bpass -compose multiply -composite \) \
-swap 0 +delete -ift "$infile" -compose plus -composite \
${inname}_bandenhance_${inner}_${outer}.$suffix
These are different results from what I get with those settings in ImageJ. Unfortunately, I do not know what they are doing. The ImageJ results look more like low pass filtering to me than what I know as band enhanced/band pass. See https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=12&cad=rja&uact=8&ved=2ahUKEwjJvoWD6L7eAhXJslQKHf1jArgQFjALegQICBAC&url=https%3A%2F%2Fcanvas.instructure.com%2Ffiles%2F6907524%2Fdownload%3Fdownload_frd%3D1&usg=AOvVaw2ws15jPD6C2-yAkfHmHYMH and https://www.scribd.com/doc/51981950/Frequency-Domain-Bandpass-Filtering-for-Image-Processing
In ImageJ, perhaps they are using a Butterworth filter or larger Gaussian blur. Or perhaps they are only processing the intensity channel from say HSI or HSV or LAB.
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 -
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%
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.
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