Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
convert -size x100 -font "Century-Schoolbook-L-Bold-Italic" -background white -stroke black -strokewidth 1 label:"my label message" "output.png"
So, if "Century-Schoolbook-L-Bold-Italic" is unavailable, I'd like to specify the next font: "Droid-Serif-Bold-Italic", and if that isn't available, then: "URW-Bookman-L-Demi-Bold-Italic" and so on.
Thanks.
Last edited by teracow on 2016-06-17T13:44:58-07:00, edited 1 time in total.
#!/bin/bash
# Return the first preferred font name available to ImageMagic. If none found then return "".
function WantedFonts
{
local font_list=""
font_list+="Century-Schoolbook-L-Bold-Italic\n"
font_list+="Droid-Serif-Bold-Italic\n"
font_list+="FreeSerif-Bold-Italic\n"
font_list+="Nimbus-Roman-No9-L-Medium-Italic\n"
font_list+="Times-BoldItalic\n"
font_list+="URW-Palladio-L-Bold-Italic\n"
font_list+="Utopia-Bold-Italic\n"
font_list+="Bitstream-Charter-Bold-Italic\n"
echo -e "$font_list"
}
function FirstPreferredFont
{
local preferred_fonts=$(WantedFonts)
local available_fonts=$(convert -list font | grep "Font:" | sed 's| Font: ||')
local first_available_font=""
while read preferred_font ; do
while read available_font ; do
[ "$preferred_font" == "$available_font" ] && break 2
done <<< "$available_fonts"
done <<< "$preferred_fonts"
if [ ! -z "$preferred_font" ] ; then
echo "$preferred_font"
else
# uncomment 2nd line down to return first installed font if no preferred fonts could be found.
# for 'convert -font' this isn't needed as it will use a default font if specified font is "".
#read first_available_font others <<< $available_fonts
echo "$first_available_font"
fi
}
echo "$(FirstPreferredFont)"
and it seems to do what I need. Have to put it in the main script now.
update: modified font name separation char
Last edited by teracow on 2016-06-21T10:50:29-07:00, edited 2 times in total.
teracow wrote:I'm trying to keep the code portable so as to reduce the config-work required for the end-user.
I have a couple IM scripts that use fonts which don't reside on all my computers. I keep the scripts in their own folders, and keep a copy of the OTF or TTF font file right in the same folder. To use the fonts in the script, I just name the font file itself when setting the font in the IM command like...
I use these IM commands and scripts on Windows machines, and it works great. It takes a tiny bit of storage, maybe 50K to 200K for a font file, but it doesn't require installing the font in the computer where I'm running the IM command. I don't know if it works like this in a *nix system, but I can't see why it wouldn't. Maybe you can get some use out of this technique.
teracow wrote:I'm trying to keep the code portable so as to reduce the config-work required for the end-user.
I have a couple IM scripts that use fonts which don't reside on all my computers. I keep the scripts in their own folders, and keep a copy of the OTF or TTF font file right in the same folder. To use the fonts in the script, I just name the font file itself when setting the font in the IM command like...