Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 47,284

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
Massive Big Sur Slide May Keep Highway 1 Closed for a Year “It’s definitely breathtaking, it’s definitely massive,” she said of the landslide caused by millions of tons of dirt and rock tumbling down the coastal hillside. Officials say the slide created a new 16-acre land mass sticking out from the ...
Tarkloon
4 hours, 49 minutes ago
Views: 157 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
The Major’s #MemorialDay Message (Especially for #Millenials) for 2017 Well, The Major’s meat-space doppelganger has FINALLY, after decades, gotten the proper medication to treat his ailment! And the best part? It feels like it’s actually working! (Say Hallelujia!) It’s almost like “The Sleeper Has Awakened!”… Now by now, ...
The Major
13 hours, 1 minute ago
Views: 212 • Comments: 0 • Rating: 0
Tweets: 7 • Share to Facebook
Shares: 0
Comments: 0
: 0
YOUR TAX DOLLARS at HATE: ICE Has Made Over 41,000 Arrests in Trump’s First 100 Days  n the first 100 days that Donald Trump has been in office, arrests for immigration violations have increased 38 percent over to the same period in 2016, according to figures Immigration and Customs Enforcement released Wednesday. More than ...
Birth Control Works
21 hours, 21 minutes ago
Views: 417 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Mike Pence and the Delicate Art of Protest.blog.timesunion.comHOFFMAN FILESMike Pence and the delicate art of protest.By Rob Hoffman on May 25, 2017 at 5:30 AM3Is there a right that is more fundamental to being an American than the right to peaceably assemble? Its prominence in the Bill ...
rhoffman
2 days, 5 hours ago
Views: 469 • Comments: 3 • Rating: -5
Tweets: 2 • Share to Facebook
Shares: 1
Comments: 0
: 1
READ THE WHOLE THING: Sexual Violence Is a Hate Crime - National Organization for Women I strongly believe violence against women, and particularly sexual violence, is a hate crime – and that may surprise people, even feminists. On October 2, 2006 a man walked into an Amish schoolhouse in Lancaster, County Pennsylvania and shot ...
Birth Control Works
2 days, 5 hours ago
Views: 371 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
What I Learned After My Study on Men Secretly Removing Condoms Went Viral But it struck a chord, and somehow managed to trigger an international conversation about assholes who remove condoms during sex without their partners' permission. (Some people call this "stealthing," but I think the term trivializes the harm.) The paper ...
Birth Control Works
2 days, 16 hours ago
Views: 432 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
‘Racist’ Flyers Urge Black Chicagoans to Help Deport Latino Neighbors - Pilsen - DNAinfo Chicago CHICAGO — A South Side alderman is slamming a flyer found in neighborhoods around the city asking black Chicagoans to report suspected undocumented residents to immigration agents. The flyer says that "Sanctuary city Policies endanger the lively hood[sic] of ...
Birth Control Works
2 days, 16 hours ago
Views: 333 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
You Have One Last Chance to Repent, Sean Hannity….Help me force Sean Hannity to repent. If he doesn't, The Major will bring incredible the damage to Mr. Hannity using the new weapons of The Internet. I tried to warn you, Sean. You didn't listen then. If you choose ...
The Major
3 days, 13 hours ago
Views: 472 • Comments: 0 • Rating: 0
Tweets: 2 • Share to Facebook
Shares: 0
Comments: 0
: 0
Doctors Argue That Female Genital Mutilation Is Protected Under First Amendment Two doctors in Detroit, along with one of their wives, are about to take the first religious defense of female genital mutilation to a US Federal court. The case stems from a FBI investigation into Dr. Jumana Nagarwala after ...
Birth Control Works
3 days, 15 hours ago
Views: 600 • Comments: 0 • Rating: 3
Tweets: 3 • Share to Facebook
Shares: 1
Comments: 0
: 1
Letters From Women Pleading for Abortion, Sent in 1917, Mirror Emails Sent Today In the early 1900s, desperate American women wrote letters to the founder of Planned Parenthood begging for help with unwanted pregnancies. A century later, they're sending eerily similar messages to an international abortion-by-mail service. "I'm in the family way ...
Birth Control Works
3 days, 16 hours ago
Views: 562 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 1
Comments: 0
: 1