Imagemagick change label font and squash - image

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%

Related

imagemagic: stacking of the images using convert and montage

My bash script uses convert of the image magic to stack horizontally two types of the images producing 2xN multi-image chart:
convert \( "${output}/type1*.png" -append \) \( "${output}/type2*.png" -append \) +append -background white -alpha deactivate ${output}/summary.png
how would it be possible to add border of the selected dimensions between stacked images in the manner as I may do via montage -mattecolor $color_id ?
montage \( "${output}/type1*.png" \) \( "${output}/type2*.png" \) -geometry 800x600+1+1 -tile x2 -frame 4 -background white -mattecolor lightgoldenrod2 -mode Frame -bordercolor white ${output}/summary.png
vertical borders between each separate sections of the type1/ type2 and a horizontal border between the both parts joined in the summary:
convert \( "${output}/type1*.png" -bordercolor lightgoldenrod2 -border 0x2 -append \) \( "${output}/type2*.png" -bordercolor lightgoldenrod2 -border 0x2 -append \) -bordercolor lightgoldenrod2 -border 2x0 +append -background white -alpha deactivate ${output}/summary.png

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 convert with font Helvetica

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.

Imagemagick images next to each other with proper margin

I am trying to create a png file with a transparent background, in which I put images next to each other.
My command so far is this:
convert --% -bordercolor none -background none -gravity center logo.png -border 5x5 ( img1.jpg img2.jpg img3.jpg -border 5x5 +append ) ( img4.jpg img5.jpg img6.jpg -border 5x5 +append ) -append -border 5x5 -resize 720x480 output.png
it creates me this image
how do I have to change my command to make the image appear as following?
(I made the background grey so one can see the white text, the background shall be transparent later on)
I tried Mark Setchells suggestion the command so far looks like this:
convert -background none -bordercolor none -gravity west \
C:\xampp\htdocs\app\storage\images\Img_1.jpg label:"1" +swap -append label:"text 1" -append -write miff:- +delete \
C:\xampp\htdocs\app\storage\images\Img_2.jpg label:"2" +swap -append label:"text 2" -append -write miff:- +delete \
C:\xampp\htdocs\app\storage\images\Img_3.jpg label:"3" +swap -append label:"text 3" -append -write miff:- +delete \
C:\xampp\htdocs\app\storage\images\Img_4.jpg label:"4" +swap -append label:"text 4" -append -write miff:- +delete \
C:\xampp\htdocs\app\storage\images\Img_5.jpg label:"5" +swap -append label:"text 5" -append -write miff:- +delete \
C:\xampp\htdocs\app\storage\images\Img_6.jpg label:"6" +swap -append label:"text 6" -append miff:- |
montage -set label '' miff:- -background pink -tile 3x2 -geometry +15+5 miff:- |
convert -size 800x500 xc:gray80 -gravity center miff:- -composite -gravity north C:\xampp\htdocs\app\storage\images\logo.png -geometry +0+30 -composite C:\xampp\htdocs\app\storage\images\result.png
You can do it many ways. Here is one:
Method 1
#!/bin/bash
convert -background none -bordercolor none -gravity west \
\( 1.png label:"1" +swap -append label:"text 1" -append -border 5x5 \) \
\( 2.png label:"2" +swap -append label:"text 2" -append -border 5x5 \) +append \
\( 3.png label:"3" +swap -append label:"text 3" -append -border 5x5 \) +append \
\( \
\( 4.png label:"4" +swap -append label:"text 4" -append -border 5x5 \) \
\( 5.png label:"5" +swap -append label:"text 5" -append -border 5x5 \) +append \
\( 6.png label:"6" +swap -append label:"text 6" -append -border 5x5 \) +append \
\) -append \
-gravity center -extent 800x550 \
-gravity north logo.png -geometry +0+30 -composite result.png
Method 2
This way you can use the first convert command to put the labels above and below each image and then stream all 6 labelled images into montage to do the grid layout (on pink) for you and from there back into another convert to create the gray background canvas and write the logo on at the top.
#!/bin/bash
convert -background none -bordercolor none -gravity west \
1.png label:"1" +swap -append label:"text 1" -append -write miff:- +delete \
2.png label:"2" +swap -append label:"text 2" -append -write miff:- +delete \
3.png label:"3" +swap -append label:"text 3" -append -write miff:- +delete \
4.png label:"4" +swap -append label:"text 4" -append -write miff:- +delete \
5.png label:"5" +swap -append label:"text 5" -append -write miff:- +delete \
6.png label:"6" +swap -append label:"text 6" -append miff:- |
montage -set label '' miff:- -background pink -tile 3x2 -geometry +15+5 miff:- |
convert -size 800x500 xc:gray80 -gravity center miff:- -composite -gravity north logo.png -geometry +0+30 -composite result.png
Sorry, I have no idea or understanding why Windows is so poor at parsing the command, but after much fiddling around, the following seems to work - I have no idea why!
convert -background none -bordercolor none -gravity west ^
1.png label:"1" +swap -append label:"text 1" -append -write miff:- +delete ^
2.png label:"2" +swap -append label:"text 2" -append -write miff:- +delete ^
3.png label:"3" +swap -append label:"text 3" -append -write miff:- +delete ^
4.png label:"4" +swap -append label:"text 4" -append -write miff:- +delete ^
5.png label:"5" +swap -append label:"text 5" -append -write miff:- +delete ^
6.png label:"6" +swap -append label:"text 6" -append miff:- | montage -set label "" miff:- ^
-background pink -tile 3x2 -geometry +15+5 miff:- | convert -size 800x500 ^
xc:gray80 -gravity center miff: -composite -gravity north logo.png -geometry +0+30 -composite result.png

Resources