Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 49,161

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
Weekend Box Office: ‘Black Panther’ Bounds to Record-Shattering $218M-Plus Bow In a defining moment for Hollywood, Disney and Marvel Studios' Black Panther exploded at the Presidents Day box office, bounding to a record-shattering estimate of $192 million for the three-day weekend and a projected $218 million-plus for the four-day ...
Thanos
4 hours, 19 minutes ago
Views: 63 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Brandi Carlile - the Joke (Official Video) From the album "By The Way, I Forgive You" available now. elektrar.ec Directed by Danny Clinch Produced by Lindha Narvaez for MILKT Choreography by Peter Leung Ballet sequence filmed by Middle Table Productions Connect with Brandi: brandicarlile.com facebook.com @brandicarlile ...
Thanos
1 day ago
Views: 113 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
School Shooter Nikolas Cruz Belonged to White Supremacist GroupThis my surprised face.... BREAKING: Nikolas Cruz, alleged perpetrator in the deadly school shooting in Parkland, Florida, was associated with white supremacist group Republic of Florida &amp; participated in the group’s training exercises, according to the group’s leader. More info: ...
Scottish Dragon
3 days, 8 hours ago
Views: 353 • Comments: 2 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Your Medicine Cabinet Knows What AIls Youblog.timesunion.com HOFFMAN FILESYour medicine cabinet knows what ails you.By Rob Hoffman on February 15, 2018 at 5:27 AM1We all fancy ourselves experts when it comes to the human condition. We see our fellow human beings as open books, and we ...
rhoffman
3 days, 10 hours ago
Views: 373 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 1
Comments: 0
: 1
A.G. Schneiderman Files Civil Rights Lawsuit Against the Weinstein Companies, Harvey Weinstein, and Robert Weinstein NEW YORK – New York Attorney General Eric T. Schneiderman today filed suit against The Weinstein Company (“TWC”), Harvey Weinstein, and Robert Weinstein for egregious violations of New York’s civil rights, human rights, and business laws. The suit, filed ...
Thanos
1 week ago
Views: 887 • Comments: 0 • Rating: 0
Tweets: 5 • Share to Facebook
Shares: 2
Comments: 0
: 2
Portugal. The Man - Keep on (Official Video) Portugal. The Man - Keep On Video conceptualized, created and directed by Paulin RoguesFollow Paulin at instagram.com Catch Portugal. The Man on tour:portugaltheman.com WOODSTOCK available now!atlantic.lnk.to Follow Portugal. The ManWebsite: portugaltheman.comFB: facebook.com IG: instagram.comTW: @portugalthemanSC: SoundCloudYT: youtube.comTumblr: portugaltheman.tumblr.com ...
Thanos
1 week, 1 day ago
Views: 1,028 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Marvel’s Jessica Jones - Season 2 Jessica Jones is back as New York City’s tough-as-nails private investigator. Although this time, the case is even more personal than ever before. Fueled by a myriad of questions and lies, she will do whatever it takes to uncover ...
Thanos
1 week, 1 day ago
Views: 937 • Comments: 1 • Rating: 2
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Deadpool 2 Teaser Trailer - Red Band (2018) Ryan Reynolds, Josh Brolin The Merc with a Mouth takes a pop at Cable, Toy Story and Justice League in this teaser for the upcoming Deadpool sequel. Watch more entertainment and game trailers here!YouTube Watch the latest from IGN here!YouTube ------------------------------­----Follow IGN for ...
Thanos
1 week, 1 day ago
Views: 925 • Comments: 1 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Poll: Number of Conservative-Leaning States Drops to 39 (CN) – The number of conservative-leaning states has dropped from 44 to 39, according to a new Gallup poll released Wednesday. The survey, conducted over a number of polls taken throughout the year, found that 35 percent of Americans ...
Thanos
1 week, 3 days ago
Views: 1,033 • Comments: 0 • Rating: 3
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Shock Tactics: Why ‘Higher Risk’ Human Targets Get Stunned With Tasers NEW YORK – The maker of the Taser says the electroshock weapon is the safest tool on a police officer’s belt – with a few caveats. In pages of warnings, Axon Enterprise Inc advises police to beware that some ...
Thanos
1 week, 4 days ago
Views: 1,039 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0