Optimizing Logotype Generation

One of the bottlenecks Logoshi.com experienced after being featured on multiple blogs simultaneously was the generation of the text portion of the logos.  I wanted to generate type as large as possible within a fixed container size.  I had been approaching the problem with commands like this:

convert -size 1000x500 -background 'transparent' -font 'font.ttf' -kerning 0 -fill '#000000' -gravity center label:' Company ' text-image.png

It turns out that is incredibly inefficient as the output image dimensions increase.  Convert tries to fit the text within the given dimensions starting with a small point size increasing it over and over until it just barely fits within the desired dimension.  Performance is pretty good with small image sizes on my cheap-o server, but once you start getting to 1000x500 sizes, things noticeably slow down.  After reading the docs, I realized this was the wrong approach.  The solution is to specify a point size for the text and not specify the ultimate image dimension until a final resize command.  The command to generate the text portion of the logos is now something like this:

convert -background 'transparent&apos -pointsize 500 -density 72 -font 'font.ttf' -kerning 0 -fill '#000000' -gravity center label:' Company ' -resize 1000x500\> -size 1000x500 xc:transparent +swap -gravity center -composite text-image.png

This command doesn’t specify the image dimensions and instead specifies the point size to draw the text.  The resulting image file is then resized down to the desired dimensions.  In informal testing, this is about 10x faster.

Make Your Logo!

July 17 2014

Back to the Blog