Fast Image Overlay (constant overlay image)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dkode
Posts: 9
Joined: 2018-04-23T11:26:53-07:00
Authentication code: 1152

Fast Image Overlay (constant overlay image)

Post by dkode »

I want to overlay an image over a background image.

In my case the overlay image is constant (for example a logo or signature) but background image is variable.
Is there any way to leverage the fact that overlay image is constant?
I tried using .mpc file but gains are negligible.
My primary concern in performance as i have to do this in runtime/online .

There is other option where i can use draw command in place of overlay. But i have not found a consistent way to figure out font dimensions when rendered wrt to pointsize. I tried the methods described in imagemagick doc for font metric calculation. But those are 2-3 pixels inconsistent when rendered.
If anybody has better font metrics calculation method, please share.
Also Does draw method first creates image and overlay on background, or does it change the background pixels in place without creating any temporary image?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fast Image Overlay (constant overlay image)

Post by snibgo »

If your overlay is small compared to the input background and output, then reducing the time needed to read the overlay to zero would not reduce the overall time by much.

If your overlay is large, and you can read many input backgrounds into memory at the same time, you can read the overlay just once and use "-layers composite", then write the outputs.

For details of how "-draw" works, see draw.c.
snibgo's IM pages: im.snibgo.com
dkode
Posts: 9
Joined: 2018-04-23T11:26:53-07:00
Authentication code: 1152

Re: Fast Image Overlay (constant overlay image)

Post by dkode »

Thanks snibgo,

But setup is over HTTP, so i get to do all this whenever a request comes, hence cannot read multiple images at once.
In my case overlay image is small.

Also sometimes i may need to resize my overlay image when background image is not of predefined size, So any option available for that like svg draw or something like that.
Post Reply