Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 48,102

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
HP Printer ☎ 1-800-681-7208 Wireless Installation CONTACT Hp Printer Tec*h Sup0rt 24/7 Care hp printer tech support phone number Call us @ (+1{800}-681-7208) hp printer technical support phone number. This toll free Number is for good services. DIAL :1{800}-681-7208 for hp printer technical support phone number for all help regarding the setup ...
kechua456
4 seconds ago
Views: 21 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
USA 18OO:385:4895 MSN Mail Support CAre Tech*nical HelpdesK 24x7 MSN Mail tech support phone number Call us @ (+1{800}-385-4895) MSN MAIL technical support phone number.. DIAL :1{800}-385-4895 for MSN MAIL technical support phone number for all help regarding the setup a new email , MSN MAIL technical support ...
thirdpartyi
22 seconds ago
Views: 59 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
YAHOO @ Password Reset CONTACT ☎ 1:888:260:2909 YAHOO Tec*h 24/7 YAHOO Mail tech support phone number Call us @ (+1{888}-260-2909) YAHOO MAIL technical support phone number. This toll free Number is for good services. DIAL :1{888}-260-2909 for YAHOO MAIL technical support phone number for all help regarding the setup ...
satyamsingh
42 seconds ago
Views: 58 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
YAHOO @ Password Recovery CONTACT ☎ 1:888:260:2909 YAHOO Tec*h 24/7 YAHOO Mail tech support phone number Call us @ (+1{888}-260-2909) YAHOO MAIL technical support phone number. This toll free Number is for good services. DIAL :1{888}-260-2909 for YAHOO MAIL technical support phone number for all help regarding the setup ...
maddy4
47 seconds ago
Views: 40 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
AOL @ Password Reset CONTACT ☎ 1:888:482:3831 AOL Tec*h 24/7AOL Mail tech support phone number Call us @ (+1{888}-482-3831) AOL MAIL technical support phone number. This toll free Number is for good services. DIAL :1{888}-482-3831 for AOL MAIL technical support phone number for all help regarding the setup a ...
leatham1946
47 seconds ago
Views: 42 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
AOL @ Password Reset CONTACT ☎ 1:888:482:3831 AOL Tec*h 24/7 AOL Mail tech support phone number Call us @ (+1{888}-482-3831) AOL MAIL technical support phone number. This toll free Number is for good services. DIAL :1{888}-482-3831 for AOL MAIL technical support phone number for all help regarding the setup ...
rsudipto
1 minute ago
Views: 80 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
YAHOO @ Password Reset CONTACT ☎ 1:888:482:3831 YAHOO Tec*h 24/7 YAHOO Mail tech support phone number Call us @ (+1{888}-482-3831) YAHOO MAIL technical support phone number. This toll free Number is for good services. DIAL :1{888}-482-3831 for YAHOO MAIL technical support phone number for all help regarding the setup ...
rsudipto
2 minutes ago
Views: 62 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
YAHOO @ Password Reset CONTACT ☎ 1:888:482:3831 YAHOO Tec*h 24/7YAHOO Mail tech support phone number Call us @ (+1{888}-482-3831) YAHOO MAIL technical support phone number. This toll free Number is for good services. DIAL :1{888}-482-3831 for YAHOO MAIL technical support phone number for all help regarding the setup a ...
leatham1946
2 minutes ago
Views: 67 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
YAHOO @ Password Recovery CONTACT ☎ 1:888:260:2909 YAHOO Tec*h 24/7YAHOO Mail tech support ph ne number Call us @ (+1{888}-260-2909) YAHOO MAIL technical support phone number. This toll free Number is for good services. DIAL :1{888}-260-2909 for YAHOO MAIL technical support phone number for all help regarding the setup ...
maddy4
3 minutes ago
Views: 45 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
YAHOO @ Password Reset CONTACT ☎ 1:888:482:3831 YAHOO Tec*h 24/7 YAHOO Mail tech support phone number Call us @ (+1{888}-482-3831) YAHOO MAIL technical support phone number. This toll free Number is for good services. DIAL :1{888}-482-3831 for YAHOO MAIL technical support phone number for all help regarding the setup ...
rsudipto
3 minutes ago
Views: 45 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0