Library for image editing and text insertion

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Apr 26 18:31:49 UTC 2022


On Tue, Apr 26, 2022 at 05:22:54PM +0000, Alexander Zhirov via Digitalmars-d-learn wrote:
> It is necessary to write a utility that will insert (x,y) text on the
> image.  It is desirable that the utility does not depend on large
> libraries, since a minimum utility size is required. I'm looking for
> something similar in C/C++, I can't find anything. Maybe there is some
> simple library on D?

Maybe use imagemagick?

	https://stackoverflow.com/questions/23236898/add-text-on-image-at-specific-point-using-imagemagick

Handling multiple image formats is generally a complex task that
requires multiple libraries, some of which may not be trivial.  Unless
you have a specific image format in mind?

Also, text rendering, in general, is an extremely complex and hairy
problem.  At the very minimum, you need a font.  If you have a bitmap
font, then it's relatively easy (just blit the characters you need onto
the image with alpha blending).  But if you're looking at TTF fonts or
similar, you're looking at the very minimum at using libfreetype to be
able to meaningfully use the font file.  Then there's the issue of font
layout, which is language-specific and may require a complex layout
engine like HarfBuzz (which requires libraries with complex
dependencies).

If utility size is of utmost importance, then the ideal case would be a
fixed image format (so only 1 library is needed to process files of that
type) with a bitmapped font (at worst, a 2nd library for reading the
font) for a specific language (so no cross-language layout issues that
requires complex layout engines). Then you can just treat the font
characters as bitmaps and alpha-blend them onto the image. Preferably,
use a monospaced bitmap font so that you can just use a fixed grid for
character placement, and not have to deal with complex font metrics,
hinting, kerning, and all of that complex stuff.  For this, maybe look
at Adam Ruppe's arsd library (https://github.com/adamdruppe/arsd) for
some lightweight modules that read common image formats and do some
primitive image manipulations.


T

-- 
People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird. -- D. Knuth


More information about the Digitalmars-d-learn mailing list