edge fade

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

edge fade

Post by dognose »

I'm trying to put 2 images, side by side, and put a slow fade between them.

Does anyone know a way to do this? I guess it involves a partial alpha gradient on one image, then pasting it on the other... I'm just not sure how to get alpha to work across
only the one edge. .
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

I am not sure I follow.

How can your fade between images that are side by side.
Is their a larger background (say a black canvas) involved?

Their are a number of techniques for 'fading' an whole image,
but you are talking about an edge.

Are you trying to join two images together to form a new single larger image?


Basically you are jsut not clear what you are trying to do.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Post by dognose »

Yes, the images would be side by side on a larger canvas, but the would overlap a little.
I'm sorry I couldn't find an example image..

I want the part that overlaps to be a fade between the two pictures.

Say they overlap by 100 pixels.. I think that what I would have to do is put a gradient
of alpha transparency on the side of one of the images, going from 100% transparent on the edge to 0% transparent in those 100 pixels.. . then be able to paste the image next to the other one. It should end up as a steady fade between the two pictures. .
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

I have not documented this process yet as I am waiting for a good example bit of code. Specifically trying to match up two images so the overlay is common and the fade between them is near invisible.

However If you know how much overlap is present between the images,
(or it doesn't really matter as they are dissimular), then you just need to
add an appropriate alpha chaneel to one edge of one image, and overlay that with the right offsets onto the other.

The best way to generate an alpha channel is generate a gradient near the edge, say the right edge of a 120x80 pixel image (adjust numbers to suit)

Linear fadeoff (gradient, then rotated)

Code: Select all

convert gradient:'[80x30]' xc:black'[80x90]' -append -rotate 90 fade_linear.png
This is not very good fade, but can be improved with a -blur to smooth things off

Code: Select all

convert gradient:'[80x20]' xc:black'[80x100]' -append -rotate 90 -blur 0x10 fade_linear_blurred.png
Or you can use a -sigmodial-contrast on a larger gradient to make it a very nice smooth curve.

Code: Select all

convert gradient:'[80x40]' -rotate 90 -sigmoidal-contrast 4x50% xc:black'[80x80]' +swap +append fade_sigmoidal.png

That above has been added as a raw construction note to 'Digital Photos' area of IM examples.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Post by dognose »

Yes, those gradients look very good, now, just for completeness, the last step..

"Now add this 'matte channel' to our image, and overlay them."

I seem to have an extra step? ?

First, I added -negate on the creation of the fade_sigmoidal...

then adding the matte channel to the first image
composite -compose CopyOpacity fade_sigmoidal.png left.gif left-fade.png

then pasting them together (the right image would already be moved into place)

composite -compose SrcOver left-fade.png right.png output.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

See 'Channels' in Im Examples.

You can do that in convert too

Code: Select all

convert  image.img   mask.img   \
               -compose CopyOpacity -composite   masked_output.img
As for overlaying them,

Code: Select all

convert  masked_ouput.img  -repage +X+Y \
               -page +X2+Y2    under_image.img \
               +swap +compose -mosaic   merged_image.img
Of course all the steps in convert can be done in a single command :-)

PS: SrcOver and Over are the same and the default (+compose)

Actually you can also use a three image composite too, though it may be a little trickier.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply