Exporting font samples as image

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?".
Post Reply
jessec
Posts: 2
Joined: 2017-02-16T11:01:40-07:00
Authentication code: 1151

Exporting font samples as image

Post by jessec »

I'm trying to create a giant image with font samples, using montage: http://www.imagemagick.org/Usage/montage/#reuse

There are about 1000 fonts and the command line interface is too short (8192 chars).

Is there a way I can write a script to do the same thing as the command line interface?
c:/xampp/htdocs/opensu/breakitbracelet/ImageMagick/magick.exe montage -pointsize 24 -background Lavender -font ABeeZee -label ABeeZee label:Abc-123 -font Abel -label Abel label:Abc-123 -font Abril-Fatface -label Abril-Fatface label:Abc-123 -font Aclonica -label Aclonica label:Abc-123 -font Acme -label Acme label:Abc-123 -font Actor -label Actor label:Abc-123 -font Adamina -label Adamina label:Abc-123 -font Advent-Pro -label Advent-Pro label:Abc-123 -font Aguafina-Script -label Aguafina-Script label:Abc-123 -font Aharoni -label Aharoni label:Abc-123 -font Akronim -label Akronim label:Abc-123 -font Aladin -label Aladin label:Abc-123 -font Aldrich -label Aldrich label:Abc-123 -font Alef -label Alef label:Abc-123 -font Alegreya -label Alegreya label:Abc-123 -font Alegreya-Sans -label Alegreya-Sans label:Abc-123 -font Alegreya-Sans-Black -label Alegreya-Sans-Black label:Abc-123 -font Alegreya-Sans-ExtraBold -label Alegreya-Sans-ExtraBold label:Abc-123 -font Alegreya-Sans-Light -label Alegreya-Sans-Light label:Abc-123 -font Alegreya-Sans-Medium -label Alegreya-Sans-Medium label:Abc-123 -font Alegreya-Sans-SC -label Alegreya-Sans-SC label:Abc-123 -font Alegreya-Sans-SC-Black -label Alegreya-Sans-SC-Black label:Abc-123 -frame 5 -geometry +2+2 -font Arial -pointsize 12 -background none -bordercolor SkyBlue c:/xampp/htdocs/opensu/breakitbracelet/montage_fonts.gif 2>&1
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Exporting font samples as image

Post by snibgo »

I don't think "magick montage" can use "-script".

I suggest you modify the command so it uses the simple "magick" command. Then you can put those commands in a "-script" file.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Exporting font samples as image

Post by fmw42 »

If on unix-like system, see Anthony's script show_fonts at http://www.imagemagick.org/Usage/scripts/show_fonts
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Exporting font samples as image

Post by GeeMack »

jessec wrote: 2017-02-16T11:04:51-07:00I'm trying to create a giant image with font samples, using montage: http://www.imagemagick.org/Usage/montage/#reuse

There are about 1000 fonts and the command line interface is too short (8192 chars).

Is there a way I can write a script to do the same thing as the command line interface?
I'm running IM 7 from a Windows 10 command prompt. This IM command works inside a "for" loop. It reads all the font names that ImageMagick can find using "magick -list font", and outputs them all as separate image samples of each font, and with file names made from the font names...

Code: Select all

for /F "tokens=1,2 delims=: " %I in ( 'magick -list font' ) do (
   if %I == Font ( magick -background white -bordercolor white -fill black ^
   -gravity center -font "%J" -pointsize 36 label:"\n %J \n" -trim -border 36x36 "font_%J.png" ) )
If something like that gets you part way, then you can run a "montage" operation on the results, or another "magick" command maybe with "-append" and "-crop" and "+append" to build the montage.

To run this from a BAT script you'd need to make all the percent signs "%" into doubles "%%".
jessec
Posts: 2
Joined: 2017-02-16T11:01:40-07:00
Authentication code: 1151

Re: Exporting font samples as image

Post by jessec »

Thanks for all your replies. I decided to use the GD library that comes with PHP because it's seems to be simpler and faster.

Code: Select all

<?php

ini_set('memory_limit','2G');
define('FONT_PATH', 'C:/Windows/Fonts/');
scandir(FONT_PATH);

$fonts = scandir(FONT_PATH);
$ttfFonts = array();
foreach($fonts as $key => $font){
    if ($font != "." && $font != ".." && pathinfo(FONT_PATH.$font, PATHINFO_EXTENSION) == "ttf"){
        $ttfFonts[] = $font;
    }
}

// Create the image
$im = imagecreatetruecolor(800, count($ttfFonts)*30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 799, count($ttfFonts)*30-1, $white);

// The text to draw
$text = 'Hello World';

// Add the text
foreach($ttfFonts as $key => $font){
    @imagettftext($im, 15, 0, 10, $key*30+15, $black, FONT_PATH.$font, rtrim($font, '.ttf').": ".$text);
}

imagegif($im, "fontsamples.gif");
imagedestroy($im);
echo "<iframe style='height: 80%; width: 800px' src='/fontsamples.gif'></iframe>";
Image

Maybe the same thing is also possible with magick. I had a problem getting it working as a PHP extension.
Post Reply