Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 49,869

As I’ve mentioned previously, every once in a while I manage to come up with a bit of code that doesn’t seem to exist elsewhere on the web, and if that code is useful I see it as a duty to share it with the world, as a way of saying thanks to all the coders who’ve helped me over the years by sharing similar bits.

Here’s one of those bits. While I was coding the Donald Trump Bumper Sticker Generator, I wanted to find a close match for the font used in the original graphic, and one way to do that is to look at a display of all the installed fonts. Since I was using Imagemagick to create these graphics, I needed to see which fonts were installed in a way that Imagemagick could use.

On a Linux system, when you install Imagemagick it includes some popular fonts like Avant Garde and Helvetica, but I ended up also installing a bunch of fonts I have on my office system, some of which came from an Adobe Font Folio CD I bought many eons ago. And in those fonts I eventually discovered the exact font used for the word “TRUMP” in our bumper sticker graphic: it’s “Akzidenz Grotesk.”

But I couldn’t find a script anywhere on the web that would just dump out a list of all the Imagemagick fonts, so I ended up writing one. (The screenshot at the top of this article shows a small section of the resulting web page.) And that’s the code I’m going to share today.

In order to run this PHP script you’ll need to have the Imagick extension installed; I won’t get into doing this because the installation method varies greatly depending on your server’s OS and the version of PHP you’re using. My advice is to Google “Installing Imagick for PHP” and find a method that suits your system.

The Font Display script is actually quite simple; so simple and short I haven’t included comments in this code. It’s just an HTML page with a small section of embedded PHP code to render the fonts when it’s loaded. The only really tricky part: to display the font samples I’m using an tag with a “data URI,” with the actual image data embedded directly inside the src attribute as a base 64-encoded string.

Also, because displaying all these fonts (I have a lot installed now!) can take a while, I used the set_time_limit() function to increase the amount of time to 300 seconds, so PHP doesn’t decide the script has been running too long and abort.

So without further ado… the code.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Display All Installed Imagick Fonts</title>
<style type="text/css">
body {
	background: white;
	padding: 10px;
}
div {
	border-radius: 5px;
	border: 1px solid #CCC;
	padding: 0;
	margin-bottom: 10px;
	font-family: 'Lucida Grande',Helvetica,Arial,sans-serif;
	font-size: large;
}
p {
	margin: 0;
	display: inline-block;
	padding: 5px;
	background: #a0a0a0;
	border-radius: 5px 0;
	color: white;
}
img {
	margin: .7em 1em 0;
}
</style>
</head>
<body>

<?php
set_time_limit(300);
$fonts = \Imagick::queryFonts();
$text = 'Grumpy wizards make toxic brew for the evil Queen and Jack.';
foreach ($fonts as $font) {
	$image = new \Imagick();
	$draw = new \ImagickDraw();
	$draw->setFont($font);
	$draw->setFillColor('black');
	$draw->setFontSize(32);
	$draw->annotation(0, 32, $text);
	$image->newImage(1200, 48, 'none');
	$image->setImageFormat('png');
	$image->drawImage($draw);
	$imgData = base64_encode($image->getImageBlob());
	echo <<<FONT
<div>
{$font}
<img src="data:image/png;base64,{$imgData}">
</div>
FONT;
}
?>

</body>
</html>

Here’s a live demo of the font display script, so you can see it in all its glory. The name at the top left of each font’s display area is the name you would pass to Imagick’s setFont() call.

Jump to top

Create a PageThis is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2016-01-01 10:29 am PST
LGF User's Guide RSS Feeds Tweet

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Square Cash Shop at amazon
as an LGF Associate!
Recent PagesClick to refresh
Trump’s Sudden Cancellation of the North Korean Summit Is a Stupendous Blunder - the DriveI can guess what worthless coins might be coming to my furnace soon. Nobel Peace prize? Pull the other one. I have repeatedly lauded Donald Trump for being ready and willing to talk directly with Kim Jong Un going back ...
Unshaken Defiance
2 hours, 47 minutes ago
Views: 64 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Eat This, Not That Other Stuffblog.timesunion.com By Rob Hoffman on May 24, 2018 at 5:29 AM2MoreA few years ago, a book came out that became very popular amongst those who spend a lot of their time dieting. The book was called Eat This, Not That. ...
rhoffman
10 hours, 2 minutes ago
Views: 120 • Comments: 0 • Rating: 0
Tweets: 2 • Share to Facebook
Shares: 1
Comments: 0
: 1
This Is the Kit - Full Performance (Live on KEXP) kexp.org presents This Is The Kit performing live in the KEXP studio. Recorded November 28, 2017. Songs:Empty No TeethBullet ProofMoonshine FreezeSolid Grease Host: Troy NelsonAudio Engineer: Kevin SuggsCameras: Jim Beckmann, Scott Holpainen & Justin WilmoreEditor: Justin Wilmore kexp.orgthisisthekit.co.uk ...
Thanos
4 days, 2 hours ago
Views: 152 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Starry Starry Night -Lianne La Havas Provided to YouTube by Warner Music Group Starry Starry Night · Lianne La Havas Loving Vincent (Original Soundtrack) ℗ 2017 Un Pundeas De Monetas, Inc. Under exclusive license to Éditions Milan Music Featured Vocals: Lianne La HavasComposer: Don McLean ...
Thanos
4 days, 2 hours ago
Views: 161 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
LGF Sunday Morning Wakeup Playlist
Unshaken Defiance
4 days, 7 hours ago
Views: 154 • Comments: 0 • Rating: 0
Tweets: 2 • Share to Facebook
Shares: 0
Comments: 0
: 0
Masterpiece Theater-Little WomenTonight Masterpiece Theater presents Little Women. This latest production promises to be a good one with some well known actors and actresses. The March girls are played by relative unknowns. Please check your local PBS stations for the times in ...
PhillyPretzel
1 week, 4 days ago
Views: 538 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Ry Cooder - the Prodigal Son (Live in Studio) "The Prodigal Son", Ry' Cooder's first new solo release in six years, is set for release May 11, 2018! Pre-order / stream "The Prodigal Son" here: found.ee Directed by Jeff Coffman Follow Ry:Official Website: rycooder.comFacebook: facebook.comInstagram: instagram.com LYRICSnow, the ...
Thanos
1 week, 5 days ago
Views: 702 • Comments: 1 • Rating: 1
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Charlie Puth - ‘How Long’ [Official Video] Download and Stream "How Long": atlantic.lnk.to Pre-Order Voicenotes: atlantic.lnk.to Exclusive VoiceNotes Merchandise Bundles Available Here: smarturl.it Follow Charlie:charlieputh.comtwitter.comfacebook.cominstagram.com THE VOICENOTES TOURwith Charlie Puth and Hailee SteinfeldTickets & VIP: charlieputh.com #VoicenotesTour Dates:07/11 – Toronto, ON – Budweiser Stage07/13 – Boston, ...
Thanos
1 week, 5 days ago
Views: 246 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Welles - Rock N Roll [Audio Only] PreOrder Welles Album "Red Trees and White Trashes" featuring "Seventeen" and "Rock N Roll"ffm.to Listen to Rock N Roll: ffm.toListen to Seventeen: ffm.to CONNECT: wellesmusic.comfacebook.cominstagram.com@wellesmusic--ROCK N ROLLdoesn't eatdoesn't sleepdoes drugsjus shrugs & says leave me beROCK N ROLLis a ...
Thanos
2 weeks, 4 days ago
Views: 318 • Comments: 1 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
WALK the MOON - Kamikaze (Official Video) Get WALK THE MOON's new album 'What If Nothing' featuring "Kamikaze" and "One Foot":iTunes - wtmband.comSpotify - wtmband.comApple Music - wtmband.comAmazon - wtmband.comGoogle Play - wtmband.comMerch Store - wtmband.com Catch WTM On Tour - wtmband.com Follow WALK THE MOON:walkthemoonband.comfacebook.com@WALKTHEMOONbandinstagram.com ...
Thanos
2 weeks, 4 days ago
Views: 851 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0