# Fading two images together

**URL:** https://discourse.julialang.org/t/fading-two-images-together/46843
**Category:** Visualization
**Tags:** question, images, visualization, video
**Created:** [September 18, 2020, 1:14pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843 "2020-09-18T13:14:49Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [September 18, 2020, 1:14pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843/1 "2020-09-18T13:14:49Z")

</div>

I’m trying make a video that includes a transition where one image fades into a different image. I would like to do this programmatically (as opposed to using GIMP or video software) so that the result is repeatable and shareable. My starting point is a set of Gadfly plots that I saved out as PNG and then combine into a video with `ffmpeg`. So the fading could potentially be done either at the plotting stage _before_ saving the images, or after.

Does anyone have any suggestions? Thanks in advance for any help!

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [September 18, 2020, 1:55pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843/2 "2020-09-18T13:55:40Z")

</div>

You could plot the images with transparency (alpha=0.8) in plots. Reduce the transparency in one image as you increase in the other, plotting both at the same time, during the transition períod.

---

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [September 18, 2020, 2:14pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843/3 "2020-09-18T14:14:36Z")

</div>

It would take a fair bit of work for me to convert the plots I have from `Gadfly` to `Plots`, but I might switch them over if there is not a clear path forward with just working with Gadfly or the resultant images. But something like you suggest was my initial plan.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [September 18, 2020, 3:13pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843/4 "2020-09-18T15:13:52Z")

</div>

Presumably gadfly can also do transparency?

---

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [September 18, 2020, 3:32pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843/5 "2020-09-18T15:32:54Z")

</div>

There are alpha keywords available. Though I don’t think there is a plot-wide parameter that would fade everything at once and some of plot elements don’t appear to accept alpha values (at least from my reading of the docs).

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [September 18, 2020, 4:02pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843/6 "2020-09-18T16:02:26Z")

</div>

Is it really better to use transparency here? Isn’t the right approach simply to mix the two images like

```julia
img = (1-a) .* img1.+ a .* img2

```

?

Maybe I have a major misapprehension about alpha and transparency, but I imagine it just mixes in the background rather than representing some inherent property of the foreground.

---

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [September 18, 2020, 4:22pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843/7 "2020-09-18T16:22:00Z")

</div>

Ooooh, that works beautifully! I guess I never really thought too much about the difference between transparency versus simple image math. Thanks a lot!

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [September 18, 2020, 4:28pm UTC](https://discourse.julialang.org/t/fading-two-images-together/46843/8 "2020-09-18T16:28:48Z")

</div>

Note that this only works if gamma is 1.
