Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 51,335

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.





Display All Installed Imagick Fonts




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}

FONT; }

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
Oxford Suspends Research Funding From China’s Huawei LONDON (AP) — Oxford University says it is suspending research grants and funding donations from Huawei amid growing security concerns about the Chinese telecom giant. It’s another setback for Huawei’s image in Europe, an important market for the company, ...
Thanos
2 days, 18 hours ago
Views: 161 • Comments: 0 • Rating: 1
Tweets: 11 • Share to Facebook
Shares: 0
Comments: 0
: 0
Season 3 Premiere of VictoriaFor those who are interested Season 3 of Victoria premieres this evening. Please check your local listings for times. Main PBS website:pbs.org
PhillyPretzel
1 week ago
Views: 244 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Ten Reasons Why Gold Will Remain Above $1250 in 2019Fun fact- A healthy economy drops gold lower over time. Read with caution As far as investing goes, I read an indictment of economic policy from Trump in this. After a healthy consolidation period below strong resistance around the $1300 ...
Unshaken Defiance
1 week, 1 day ago
Views: 328 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Season Pass for Victoria Season 3 at AmazonOT I am still surprised that there are people complaining about Victoria Season 3 on Amazon. The 3rd season of Victoria will start on January 13, 2019. I again wrote a review explaining the basic season pass rules and it ...
PhillyPretzel
1 week, 1 day ago
Views: 300 • Comments: 0 • Rating: 1
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Ghost-Note - Can’t Get Right - Old Growth Sessions @Pickathon 2017 S02E08 Old Growth Series - Season 2 - Episode 8 Outside Magazine presents Ghost-Note in this episode of the Pickathon Old Growth Series. Visit Outside Magazine (outsideonline.com) on the 1st Thursday of every month for a new Old Growth Series ...
Thanos
2 weeks, 1 day ago
Views: 475 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Clean Bandit - Baby (Feat. Marina & Luis Fonsi) [Official Video]Download or stream now: atlanti.crTaken from our new album "What Is Love?" - out now: atlanti.cr Click here to subscribe: bit.ly Follow us:Website: cleanbandit.co.ukFacebook: facebook.com Twitter: twitter.com Instagram: instagram.comSoundcloud: SoundCloudSpotify: atlre.co.uk
Thanos
2 weeks, 1 day ago
Views: 536 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Khruangbin - Maria También (Live on KEXP)kexp.org presents Khruangbin performing "Maria También" live in the KEXP studio. Recorded April 26, 2018. Host: Cheryl WatersAudio Engineers: Tim Iseler & Kevin Suggs Cameras: Alaia D'Alessandro, Scott Holpainen & Justin WilmoreEditor: Justin Wilmore kexp.orgkhruangbin.com
Thanos
2 weeks, 1 day ago
Views: 644 • Comments: 0 • Rating: 2
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
kokoroko - abusey junction // we out here Follow - Kokoroko - bit.lyWatch - We Out Here A LDN Story - bit.lyBuy - We Out Here - bit.ly A primer on London’s bright-burning young jazz scene, this new compilation brings together a collection of some of its ...
Thanos
2 weeks, 1 day ago
Views: 546 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Cyber Phrenology - How Is It a Thing?I'm not a computer maven. So, I apologize in advance if this post is old news for some. It is a shallow water dive into the world of influencing public opinion via memes and social media postings.I came across this ...
qubit2020
2 weeks, 2 days ago
Views: 486 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Become a Better Photographer With This 52-Week Photo ChallengeFrom pros to the most green amateur, this is excellent advice. Now let me add a few (free or almost free) essential apps for your cell phones to help. Most people don't need to buy a camera, they already have ...
Unshaken Defiance
2 weeks, 4 days ago
Views: 715 • Comments: 1 • Rating: 4
Tweets: 0 • Share to Facebook
Shares: 2
Comments: 0
: 2