Page 1 of 1

How to put one image over another one?

Posted: 2017-03-15T18:38:19-07:00
by Airon65
I want to put one image over/under another one. For example:

Code: Select all

Magick::Image img1( "images/image1.png" );
Magick::Image img2( "images/image2.png" );

img1.draw( img2, 50, 100 ); // <-- 50x100 - my desirable position for placing img2

img1.write( "output.png" );
How can I get it?

Re: How to put one image over another one?

Posted: 2017-03-15T19:11:25-07:00
by snibgo
Your previous post viewtopic.php?f=23&t=31571 showed a correct use of img.draw. And the doc http://www.imagemagick.org/Magick++/Image++.html says that's the only way to use it: with a list of Drawable objects. The list can contain only one element.

In that doc, click on Drawable to get a page of Drawable objects. One of those involves an image with x and y coordinates.

Re: How to put one image over another one?

Posted: 2017-03-16T07:07:08-07:00
by Airon65
Sorry, but I don't understand your answer :) I understand that I need to draw it as a list (std::vector) of drawables. But I don't understand how can I do it:

Code: Select all

std::vector < Drawable > arr;
arr.push_back( DrawableImage( img1, 50, 100 ) ); // <-- I don't know how to add an image to the list

img2.draw( arr );

Re: How to put one image over another one?

Posted: 2017-03-16T07:33:12-07:00
by snibgo
I don't use C++ so I don't use Magick++. But it took me only five minutes to find out how to do it, by following the documentation trail I showed you.

I strongly suggest you read the documentation. It isn't always perfect, but in this case at least it led to the solution:

Code: Select all

img1.draw( DrawableCompositeImage( 50, 100, img2 ));