Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 50,785

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
E-Cig Co. Put Viagra, Cialis in Vape Liquids—the FDA Is Throbbing Mad The US Food and Drug Administration made clear on Thursday, October 11 that it has a major bone to pick with an electronic-cigarette vendor that illegally pumped prescription erectile dysfunction drugs into unapproved e-liquid products intended for vaping. The ...
Thanos
2 days, 15 hours ago
Views: 169 • Comments: 0 • Rating: 0
Tweets: 2 • Share to Facebook
Shares: 0
Comments: 0
: 0
Answering Voter Guide Questions as a Candidate So, my county newspaper, the Bridgeport, NE News-Blade sent me a questionnaire to create a voter guide for village voters asking my positions on issues in my town. I suppose I could expound on those for many pages, but ...
Anymouse 🌹
1 week, 1 day ago
Views: 577 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Marvel’s Daredevil: Season 3 - Meet BullsEye See the origin story of Bullseye in Marvel's Daredevil Season 3, premiering exclusively on Netflix October 19, 2018. Watch Marvel's Daredevil on Netflix: netflix.com #Netflix #MarvelsDaredevil #CharlieCoxSUBSCRIBE: bit.ly About Netflix:Netflix is the world's leading internet entertainment service with 130 ...
Thanos
1 week, 4 days ago
Views: 655 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
St. Vincent - Slow Slow Disco (Audio)Songs are living things. They grow, they evolve, they change their moods and personalities over time. The latest version of 'Slow Disco' originally found on MASSEDUCTION. Upcoming Live Shows: ilovestvincent.com Connect with St. Vincent:instagram.com@st_vincentfacebook.com
Thanos
2 weeks, 1 day ago
Views: 780 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Sarah Palin’s Son Arrested on Domestic Violence Charges Sarah Palin's oldest son, Track Palin, was arrested Friday on domestic violence charges, Alaska State Troopers said. Troopers responded to his home in Wasilla at 10:37 p.m. after a report of a disturbance. Palin allegedly assaulted an acquaintance, then ...
Thanos
2 weeks, 3 days ago
Views: 785 • Comments: 1 • Rating: 0
Tweets: 2 • Share to Facebook
Shares: 0
Comments: 0
: 0
Elvis Costello & the Imposters - Suspect My Tears (Audio) "Suspect My Tears" from the forthcoming album Look NowPre-order the new album Look Now:Official Store (signed + exclusive merch): found.eeAmazon (CD + vinyl): found.eeiTunes (digital download): found.eeSpotify (pre-save): found.eeApple Music (pre-add): found.ee Listen to “Suspect My Tears”:iTunes: found.eeSpotify: found.eeApple ...
Thanos
2 weeks, 4 days ago
Views: 768 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Dark Phoenix In DARK PHOENIX, the X-MEN face their most formidable and powerful foe: one of their own, Jean Grey. During a rescue mission in space, Jean is nearly killed when she is hit by a mysterious cosmic force. Once she ...
Thanos
2 weeks, 6 days ago
Views: 810 • Comments: 1 • Rating: 1
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0