OpenImageIO/oiio — pull request #392 by lgritz (2012-07-04 04:34:52+00:00)
Title: Review: Basic text rendering into imges with ImageBufAlgo::render_text and oiitool --text

Requested feature from work. I think adding this lets somebody get rid of some other tool.

IBA::render_text() is a very basic "render text into the image pixels" functionality, exposed on the command line as oiiotool --text. You can fully trick it out with optional arguments like:

oiiotool --create 640x480 3 --text:x=20:y=400:size=24:font="Ariel Narrow.ttf" "Hello, world. This is my text." -o out.exr

Functionality is very limited -- all you have control over is font name, size, position, color, and the text. There's no formatting or wrapping, and text that ends up off the edge of the image just disappears. But this set of functionality is still really handy if you're just trying to slap a quick annotation on an image from the command line.

I used Freetype for the font rendering. It's found automatically at build time, and if it's not present the render_text function just does nothing.

Currentlyt, if you want anything but the default font, you generally need to give a full pathname to the font file. It tries to be clever in that if you only give the filename but not the full path (like I did above), it checks a default directory for it. But it's not like it really does any kind of comprehensive search. We may want to beef that up, but I figured that this was good enough for an initial code review and seek some feedback.