Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 47,685

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
Stranger Things Season II Trailer The first trailer for Stranger Things 2 is here. It’s 1984 and the citizens of Hawkins, Indiana are still reeling from the horrors of the demogorgon and the secrets of Hawkins Lab. Will Byers has been rescued from the ...
Thanos
1 day, 8 hours ago
Views: 234 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
‘Silent Coup’: Limbaugh Says ?!?! In an impassioned commentary, Rush Limbaugh said he believes the Washington establishment - both Democrats and Republicans - are involved in a "silent coup" against President Trump. Silent coup? Wrong and wrong. As silent as Rachael Maddow, Keith Olberman ...
Unshaken Defiance
4 days, 13 hours ago
Views: 576 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Immigration: Focus LocallyIn these days of Trump and the Republicans attacking everything decent about America, it's too easy to focus on the immediate threat. Trump's Muslim band is back, but everyone is paying attention to the Republicans trying to steal our healthcare. ...
jhncsy
5 days, 12 hours ago
Views: 423 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
‘Submit to Your Husbands’: Women Told to Endure Domestic Violence in the Name of God (Australian Broadcasting Corporation) The culprits were obvious: it was the menopause or the devil. Who else could be blamed, Peter screamed at his wife in nightly tirades, for her alleged insubordination, for her stupidity, her lack of sexual pliability, her refusal to ...
Birth Control Works
6 days, 11 hours ago
Views: 767 • Comments: 0 • Rating: 2
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
West Virginia Families, Just Learning About Health-Care Access, Fear It Will Be Taken Away - Rewire In Vienna, West Virginia—just north of Parkersburg, along the Ohio River separating the two states—the only Planned Parenthood health center in the state sits among a scattering of gray and tan buildings beside the main road. A few days ...
Birth Control Works
6 days, 12 hours ago
Views: 790 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Trump Election Commissioner Used Dubious Data to Allege an “Alien Invasion” - Mother Jones Election officials and experts say there’s plenty of reason to doubt those claims.But they could still provide a blueprint for Trump’s commission, which has so far hinted at tighter restrictions on voting in the name of cracking down on ...
Thanos
6 days, 19 hours ago
Views: 741 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Inside the Middle East’s First Rape & Domestic Violence Crisis Program For the last year and a half, there’s been a new sight in the Kingdom of Bahrain. Lodged into stacks of newspapers, stuck to mirrors in restaurant bathrooms, and pinned to grocery store notice boards are small, blue-and-white fliers ...
Birth Control Works
1 week ago
Views: 810 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
First Aid Kit - My Silver LiningFirst Aid Kit perform My Silver Lining at Glastonbury 2017
Thanos
1 week, 1 day ago
Views: 831 • Comments: 0 • Rating: 0
Tweets: 2 • Share to Facebook
Shares: 0
Comments: 0
: 0
Jangada - Claudia Villela Quartet at Kuumbwa Jazz Jangada written by Claudia Villela, performed by the Claudia Villela Quartet at Kuumbwa Jazz, Santa Cruz, CA, April 15, 2013 Claudia Villela - vocals, piano, percussionCelso Alberti - drums/percussionJeff Buenz - guitarsGary Brown - bass videography by John Mountaudio ...
Thanos
1 week, 1 day ago
Views: 972 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Should NYPD Lawyers Step in to Prosecute? Protestors Say No. NEW YORK (AP) -- Arminta Jeffryes was arrested while protesting police brutality. Then the police department played an unusual role in her court case. A New York Police Department lawyer stepped in to prosecute the jaywalking charge against her, ...
Thanos
1 week, 1 day ago
Views: 1,108 • Comments: 0 • Rating: 0
Tweets: 2 • Share to Facebook
Shares: 0
Comments: 0
: 0