Question

I've written a small tool in C that generates images from data out of a database. The images are in PNG format and now I need to add some text to the image. I can't find any examples on how to create text in the PNG image. I'm using the libpng library and would like to simply add a few lines that take care of adding the text to the image before calling png_write_png.

Could anyone point me to a simple "Hello World" example where those two words are visible in the image.

Can this be done with libpng or do I need to use MagickImage or similar to achieve this?

Thank in advance

Was it helpful?

Solution

No, you cannot. libpng is a library for encoding (decoding) a raw raster image to (from) a PNG format file. It has nothing to do with high level image processing tasks. You can't expect a low level encoding/decoding library a libpng to, for example, rotate an image, detect borders, etc... even less to convert a string into a digital image (pixels), which is a very high level task that involves fonts rastering. That kind of tasks are performed in the realm of the raw image (in memory), independently of the format you chose to archive it.

To accomplish your goal you should try with some image rendering/processing library or tool; this depends on your plaform: for example, libgd. ImageMagick is a valid alternative.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top