Tech Note: A Graphic Display of All Installed Imagemagick Fonts

All at once
LGF • Views: 50,419

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
Calexico - End of the World With You (Live on KEXP) kexp.org presents Calexico performing "End Of The World With You" live in the KEXP studio. Recorded June 19, 2018. Host: MorganAudio Engineers: Martin H. Gonzalez & Julian MartlewCameras: Jim Beckmann, Alaia D'Alessandro, Scott Holpainen & Justin WilmoreEditor: Jim Beckmann ...
Thanos
3 days, 21 hours ago
Views: 134 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
LSD - Thunderclouds (Official Audio) Ft. Sia, Diplo, Labrinth Labrinth, Sia & Diplo present LSD - Thunderclouds (Official Audio) Stream "Thunderclouds" now: smarturl.itSpotify: smarturl.itiTunes: smarturl.itApple Music: smarturl.itAmazon Music: smarturl.it Learn more about LSD and sign up for the official mailing list: droppinglsd.com Lyrics: All I need is oneOne ...
Thanos
3 days, 21 hours ago
Views: 181 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Half•alive - Still Feel. [Music VIDEO] half•alive’s music video for ‘still feel.’ Save on Spotify : spoti.fi Apple Music : apple.coSoundcloud : SoundCloud find half•alive on… Instagram: instagr.amTwitter: @halfalivecoSpotify: spoti.fiSoundcloud: SoundCloudSite: halfalive.co Directed / Edited / Colored by : Josh TaylorDirector of Photography : Ryan ...
Thanos
3 days, 21 hours ago
Views: 185 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Bands and Artists I LoveSuperorganism. Your text to link...
The Artist Formerly Known as Irenicum
5 days, 16 hours ago
Views: 166 • Comments: 1 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
Dave Grohl - Play (Official Video) PLAY more at play.roswellfilms.com Pre-order limited edition vinyl bundles and stream the song: smarturl.it “PLAY” by Dave Grohl celebrates the rewards and challenges of dedicating one’s life to playing and mastering a musical instrument. Part one opens with narrated ...
Thanos
6 days, 9 hours ago
Views: 182 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
The Seshen - Distant Heart (Live on KEXP) kexp.org presents The Seshen performing "Distant Heart" live at The Little London Plane during Upstream Music Fest. Recorded June 1, 2018. Host: Kevin ColeAudio Engineer: Kevin SuggsCameras: Jim Beckmann, Alaia D'Alessandro & Justin WilmoreDirector: Scott HolpainenEditor: Alaia D'Alessandro kexp.orgtheseshen.comupstreammusicfest.com ...
Thanos
1 week, 4 days ago
Views: 785 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0
Retrograde PresidentProfit at any cost. American dream. President Trump. Blind destruction. BBC News: The Trump administration has overturned bans on the use of pesticides linked to declining bee populations and the cultivation of genetically modified crops in US national wildlife refuges. ...
Dom
1 week, 6 days ago
Views: 635 • Comments: 0 • Rating: 0
Tweets: 0 • Share to Facebook
Shares: 0
Comments: 0
: 0
David Crosby and Jason Isbell ‘Ohio’----Newport
Thanos
1 week, 6 days ago
Views: 933 • Comments: 1 • Rating: 3
Tweets: 2 • Share to Facebook
Shares: 0
Comments: 0
: 0
Activist Publishes 11,000 Private DMs Between Wikileaks and Its Supporters The DMs concern a particular group chat between the official Wikileaks account and several supporters. In the chat—dubbed “Wikileaks +10” due to number of participants—Wikileaks would coordinate smear campaigns against the group’s rivals, including journalists, according to the DMs. ...
Thanos
2 weeks, 3 days ago
Views: 1,460 • Comments: 0 • Rating: 0
Tweets: 2 • Share to Facebook
Shares: 0
Comments: 0
: 0
Capital Cities - Levitate (Visualizer)Music video by Capital Cities performing Levitate. © 2018 Lazy Hooks, LLC, under exclusive license to UMG Recordings, Inc. vevo.ly
Thanos
2 weeks, 4 days ago
Views: 1,386 • Comments: 0 • Rating: 0
Tweets: 1 • Share to Facebook
Shares: 0
Comments: 0
: 0