Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 48,489

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
The Smiths - How Soon Is Now? (Official Music Video) Watch the official music video for "How Soon Is Now"Amazon: po.stiTunes: po.stGoogle: po.stFacebook: po.st "How Soon Is Now?" was originally a B-side of the 1984 single "William, It Was Really Nothing". "How Soon Is Now?" was featured on the ...
Thanos
23 hours, 15 minutes ago
Views: 177 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
2017 Hurricanes and Aerosols Simulation This is fascinating, I recommend full screen How can you see the atmosphere? By tracking what is carried on the wind. Tiny aerosol particles such as smoke, dust, and sea salt are transported across the globe, making visible weather ...
Thanos
1 day, 2 hours ago
Views: 169 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Incredibles 2 Official Teaser Trailer The teaser trailer for "Incredibles 2" is here. Disney/Pixar's "Incredibles 2" opens in theatres in 3D June 15th, 2018. Everyone’s favorite family of superheroes is back in “Incredibles 2” – but this time Helen (voice of Holly Hunter) is ...
Thanos
2 days, 1 hour ago
Views: 248 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Deadpool’s “Wet on Wet” Teaser After surviving a near fatal bovine attack, a disfigured cafeteria chef (Wade Wilson) struggles to fulfill his dream of becoming Mayberry’s hottest bartender while also learning to cope with his lost sense of taste. Searching to regain his spice ...
Thanos
4 days, 2 hours ago
Views: 518 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Voice of America Reporter Outed as Alt-Right However, using information Fatzick himself posted on Reddit — including his age, girlfriend’s name, former employers, friends, location, educational background, and sports affiliations — this reporter was able to tie the vile posts of UncleSam4200 to the Voice of ...
Thanos
5 days, 16 hours ago
Views: 671 • Comments: 3 • Rating: 2
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Gary Clark Jr - Come Together (Official Music Video) [From the Justice League Movie Soundtrack] Official Video for "Come Together" by Gary Clark Jr. featured in the Justice League Movie trailer. In theaters November 17th 2017.Directed by Kris Merc Get the song now at garyclarkjr.com Check out the Justice League soundtrack here: lnk.to Follow ...
Thanos
1 week ago
Views: 633 • Comments: 1 • Rating: 2
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Kimbra - Top of the World (Official Music Video)New from Kimbra The new single Top of the World is available now on Apple Music, Spotify, Google Play, and more. Get the single here - kmbra.me The new studio album Primal Heart out wwide January 19th, 2018Preorder now - ...
Thanos
1 week, 1 day ago
Views: 664 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
The Barr Brothers - Song That I Heard (Live on KEXP) kexp.org presents The Barr Brothers performing "Song That I Heard" live at Breakglass Studios during POP Montreal 2017. Recorded September 16, 2017. Audio Engineer: James BenjaminCameras: Jim Beckmann, Ian Cameron & Scott HolpainenEditor: Jim Beckmann kexp.orgpopmontreal.combreakglass.ca With support from ...
Thanos
1 week, 3 days ago
Views: 730 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Left Cries Foul, but Electoral College Prevents Tyranny of the Majority I'm speechless...this is what we have to fight against: Image: constitution-1486010_960_720.jpg Author: Paul Jenkins(Paul Jenkins is editor of the anchoragedailyplanet.com, a division of Porcaro Communications) The political left and its mouthpiece, The New York Times, are still fuming over ...
Cheechako
1 week, 3 days ago
Views: 882 • Comments: 2 • Rating: 3
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Tune-Yards - Look at Your Hands (Official Video) 'Look at Your Hands' by Tune-Yards. New album 'I can feel you creep into my private life' is released January 19th 2018: smarturl.it Video by Michael SpeedFootage by Marisa Gesualdi & Jennifer SommerAdditional photos by Nate Brenner, Ginger Fierstein ...
Thanos
1 week, 5 days ago
Views: 987 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0