compsite: using full canvas

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?".
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

compsite: using full canvas

Post by dognose »

I'm blending two images together like so:

composite -blend 50x50 -geometry +100+0 image1.jpg image2.jpg +repage image-out.jpg

The output image only comes out the size of image1.jpg....

I'd like it to not clip off the side of image2.jpg in the final image.

Is there an easy way to do that?

I've seen the -mosaic option in convert, but that doesn't work here in composite.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compsite: using full canvas

Post by fmw42 »

IM uses the first image in the sequence. So try convert in place of composite as it has the reverse order for the two input images.

convert image2.jpg image1.jpg -geometry +100+0 -compose blend -define compose:args=50,50 -composite +repage image-out.jpg


see

http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/script/compose.php
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Re: compsite: using full canvas

Post by dognose »

Ok, I think I had the images 1 and 2 reversed.. but.. this doesn't solve the problem.

How do I get the canvas to expand to include both images?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compsite: using full canvas

Post by fmw42 »

In my test, it worked fine. But my smaller image was inside the larger one. The larger one was first and the smaller one was second in convert ...

For example:

convert logo: rose: -geometry +300+200 -compose blend -define compose:args=50,50 -composite +repage logo_rose.jpg

For expanding composites see -mosaic http://www.imagemagick.org/Usage/layers/#mosaic

But why do you need that. If the images don't overlap, then blending makes no sense.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: compsite: using full canvas

Post by Bonzo »

I presume his second image is partialy on and partialy off the first image due to the -geometry +100+0

So the canvas is set to the first image size and the part of the second image that is off the first image is lost.

I pressume you would need to set a large plain canvas, composite the images onto that and the do a trim ?

If not an example of what he is trying to do would help :shock:
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compsite: using full canvas

Post by fmw42 »

Bonzo wrote:I presume his second image is partialy on and partialy off the first image due to the -geometry +100+0

So the canvas is set to the first image size and the part of the second image that is off the first image is lost.

I pressume you would need to set a large plain canvas, composite the images onto that and the do a trim ?

If not an example of what he is trying to do would help :shock:

-geometry +100+0 should not put one image outside the other, unless the second image is larger than the first.

Then why not just reorder the two so the smaller image is second and will fit within the first? But perhaps he needs it the other way. In that case, he may have to crop the larger image, composite with blend and then append the remaining part. Or make a background canvas large enough to hold both and then composite blend them one at a time.

As far a I know, composite blend, whether using composite or convert only works with two images at a time and will crop off any part outside of the first image's bounds. Only mosaic will expand the canvas, but does not allow blending to my knowledge. Best to review the compose methods at http://www.imagemagick.org/script/compose.php
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: compsite: using full canvas

Post by anthony »

The -composite operator takes two images. A 'background' or 'destination' which determines the final size, and any meta-data (comments, lables etc) the image may have. Then a 'source' or 'overlay' image whcih is offset by the geometry/gravity settings for placement on the destination.

The "composite" command uses the first image as the 'source' and the second as the 'destiantion' images. As such the second image determines the final size (and any other meta data). You can thing of it as 'first' onto 'second'

The "convert" command reverses the order ans it make mutli operational processing much simplier.
That is think of it as 'current image' then overlay the next second image.

Read Image Composition
http://www.imagemagick.org/Usage/compose/



convert also provides other composition methods for more than two images, known as layering.

-flatten will just overlay each image onto a canvas large enough to hold JUST the first image. Actually it is the first images virtual canvas size which by definition includes the origin if the first image has a virtual offset.

-mosaic expands the canvas in positive directions to hold all images, and include the 0,0 location when 'page' or virtual offsets are used. As origin is included result will not have a virtual offset.

-layers merge will create a 'vitrual canvas' (with a posible positive or negative offset) that is JUST large enough to hold all the given images.

Read about them in Layering Images
http://www.imagemagick.org/Usage/layers/

Finally there is a composition operator to merge two separate sequences of images, or overlay one image with a sequence of images, known as -layers composite
http://www.imagemagick.org/Usage/anim_mods/#composite
It is introduced for handling animations, but really it can be ANY sequence of images.



There are other operators that also use composition, but they typically only used against individual images to add/remove borders or frames (basically composition to copy an image onto a larger canvas).


Now ALL the above is in IM Examples. And I will NOT repeat the above in the forums again!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Re: compsite: using full canvas

Post by dognose »

Yes, the two images are the same size, so with the offset, part of the overlayed image is getting cropped off.

-layers merge does not expand the canvas in this case.

I guess it sorta makes sense that only the base image size remains, because it's getting blended.. but, I guess I was looking for an easy way around this problem...

I guess I have to figure out what the final image size would be first.. then place the images on the canvas.
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Re: compsite: using full canvas

Post by dognose »

for an example: (with 3 images)

Image

overlap areas are highlighted, but really they should end up blending in better.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compsite: using full canvas

Post by fmw42 »

see anthony's current post at viewtopic.php?f=1&t=17787 about composite. Perhaps you can set the virtual canvas of the one image to be larger enough to hold the second image as well when you do the composite. But I am not sure if convert -compose blend is sensitive to the virtual canvas or not. One will have to try and see. see http://www.imagemagick.org/Usage/basics/#page

Anthony will be more knowledgeable that I on this issue.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: compsite: using full canvas

Post by anthony »

-layers merge should expand the final canvas to hold all the images provided.

That is its purpose. -mosaic should also work for you.

However without seeing you actual command it is hard to see what is going wrong.


As for blending. You need to actually 'blend' the images with a gradient.
See Overlapping Photos
http://www.imagemagick.org/Usage/photos/#overlap

What I am seeing looks like you are just setting the images transparency exactly the same, and overlaying, without setting a background canvas color of 'none'.

Again provide links to your actual example source images (the smaller thumbnails will do for development purposes) and the command you are trying to use, and we can see what is going on and why it is not working as expected.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: compsite: using full canvas

Post by anthony »

Fred: the convert -composite operator only uses geometry and two images (optional mask as always). it never uses virtual canvas information.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compsite: using full canvas

Post by fmw42 »

anthony wrote:Fred: the convert -composite operator only uses geometry and two images (optional mask as always). it never uses virtual canvas information.

but can one do

convert .... -compose blend ... -mosaic (or flatten) ...

such that one can use -page?

Or set the virtual canvas first with -set ... -distort SRT 0 and then use -compose blend ... -mosiac ... ?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: compsite: using full canvas

Post by anthony »

fmw42 wrote:
anthony wrote:Fred: the convert -composite operator only uses geometry and two images (optional mask as always). it never uses virtual canvas information.
but can one do

convert .... -compose blend ... -mosaic (or flatten) ...

such that one can use -page?

Or set the virtual canvas first with -set ... -distort SRT 0 and then use -compose blend ... -mosiac ... ?
I did say -composite I did not say -compose which is only a setting,
and completely independant to any positioning information.

Of course -flatten, -mosaic and all the other -layers methods all use virtual page/canvas offsets.

The -layers composite however uses BOTH to merge two sequences of images.
-geometry/-gravity (with the first images virtural canvas) for global positioning. And -page (virtual offset) for individual image positioning relative to that global -geometry position, rather than just the default +0+0 origin :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compsite: using full canvas

Post by fmw42 »

Anthony wrote:Of course -flatten, -mosaic and all the other -layers methods all use virtual page/canvas offsets.

The -layers composite however uses BOTH to merge two sequences of images.
-geometry/-gravity (with the first images virtural canvas) for global positioning. And -page (virtual offset) for individual image positioning relative to that global -geometry position, rather than just the default +0+0 origin
But do any of these methods, -flatten, -layers composite work with -compose blend, such that the result expands to hold both his images, one of which is partially off the other. That is the real issue.

P.S. I understood and was trying to make the distinction between -composite and -compose, by asking if something other than -composite could be used to do a blend and get an expanded result. I guess an experiment is in order. I just thought you might know already.

I tried this:
convert -background white -page +0-64 zelda3.png -page +0+0 lena2.png -compose blend \
-define compose:args=50,50 -mosaic tmp1.png
It did blend, but the resulting image is NOT expanded!


I tried this:
convert -background white -page +0-64 zelda3.png -page +0+0 lena2.png -compose blend \
-define compose:args=50,50 -layers merge tmp2.png
It does expand and blend the two images, but unfortunately it blends the images with background where they don't overlap.

BUT THIS SEEMS TO WORK WITH A TRANSPARENT BACKGROUND WHICH IS THEN TURNED OFF:
convert -background none -page -64-64 zelda3.png -page +0+0 lena2.png -compose blend \
-define compose:args=50,50 -layers merge -alpha off tmp3.png
Results in black background

convert -background "rgba(255,255,255,0)" -page -64-64 zelda3.png -page +0+0 lena2.png -compose blend \
-define compose:args=50,50 -layers merge -alpha off tmp4.png
Results in white background

PS2: Anthony when did -set get changed to -define for compose:args. Or am I just not remembering correctly. If it was changed, then I may have some scripts that need updating and would like to know at what release that occurred.
Post Reply