2

I need to merge a couple of images so that image2 covers parts of image1 and so on. I found the CImg library but I couldn't find out how to use it for my purposes.

Is there any other library I could use or may I achieve this with CImg?

BlackMamba
  • 1,449
  • 2
  • 12
  • 18
  • check out Magick++ http://www.imagemagick.org/Magick++/ – Reuben L. Apr 13 '14 at 13:48
  • Look at [OpenCV Library](http://docs.opencv.org/index.html). If you read the reference documentation, you will find examples on how to copy a smaller image to a sub rectangle of a bigger image. – Sammy Apr 13 '14 at 15:30
  • I already know OpenCV, but I think it has too much overhead for my rather simple purpose. On the contrary, Magick++ seems to be exactly what I need. – BlackMamba Apr 13 '14 at 20:29

1 Answers1

0

I created two images like this with ImageMagick:

convert -size 400x300 gradient:blue-yellow PNG24:gradient.png

enter image description here

convert -size 100x100 xc:fuchsia overlay.png

enter image description here

And then ran this CImg code:

#define cimg_use_png
#define cimg_display 0
#include "CImg.h"
using namespace cimg_library;
int main() {
   CImg<unsigned char> gradient("gradient.png");
   CImg<unsigned char> overlay("overlay.png");
   gradient.draw_image(150,50,overlay);
   gradient.save_png("result.png");
}

And got this:

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432