# How do you create a transparent .png using Images.jl?

**URL:** https://discourse.julialang.org/t/how-do-you-create-a-transparent-png-using-images-jl/33981
**Category:** Visualization
**Created:** [January 30, 2020, 2:25pm UTC](https://discourse.julialang.org/t/how-do-you-create-a-transparent-png-using-images-jl/33981 "2020-01-30T14:25:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![NiclasMattsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclasmattsson/32/21988_2.png) [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)
#### Post date: [January 30, 2020, 2:25pm UTC](https://discourse.julialang.org/t/how-do-you-create-a-transparent-png-using-images-jl/33981/1 "2020-01-30T14:25:44Z")

</div>

The following does not work. In Photoshop terms, it creates a .png with a (solid black) background layer instead of an ordinary layer, and background layers cannot have transparent pixels.

```julia
julia> using Images

julia> img = fill(RGBA(0,0,0,0), (10,20))
10×20 Array{RGBA{N0f8},2} with eltype RGBA{Normed{UInt8,8}}:
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) … RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) … RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0)
 RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0) RGBA{N0f8}(0.0,0.0,0.0,0.0)

julia> save("transparent.png", img)

julia> 

```

![transparent](https://global.discourse-cdn.com/julialang/original/3X/8/f/8fbcc6fe41e3894f5480dc46da2578d1596b19a4.png)

---

<div class="post-metadata">

### Author: ![NiclasMattsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclasmattsson/32/21988_2.png) [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)
#### Post date: [January 30, 2020, 3:35pm UTC](https://discourse.julialang.org/t/how-do-you-create-a-transparent-png-using-images-jl/33981/2 "2020-01-30T15:35:37Z")

</div>

Problem … solved? It turns out the layer type depends on which fill color I use, even though the alpha channel is always zero:

transparent black RGBA(0,0,0,0) =\> background layer (no transparency)  
transparent white RGBA(1,1,1,0) =\> ordinary layer (transparent)  
transparent mid gray RGBA(.5,.5,.5,0) =\> background layer (no transparency)  
transparent light gray RGBA(.9,.9,.9,0) =\> background layer (no transparency)  
transparent dark gray RGBA(.1,.1,.1,0) =\> background layer (no transparency)  
transparent any other color RGBA(.8,.2,.1,0) =\> index layer (transparent)

So transparency works if I fill with white or any other non-grayscale color. I’d like to open an issue for this inconsistency, but I’m not sure if I should open it in Images.jl, ImageMagick.jl (the underlying library on Windows) or FileIO.jl. Suggestions?

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [January 30, 2020, 6:21pm UTC](https://discourse.julialang.org/t/how-do-you-create-a-transparent-png-using-images-jl/33981/3 "2020-01-30T18:21:57Z")

</div>

```julia
img = fill(RGBA(0,0,0,0.5), (200,200));
save("/tmp/transparent.png", img)

```

This creates a semitransparent grey box for me. (I’m on macOS.)

 ![Screenshot 2020-01-30 at 18.20.26](https://global.discourse-cdn.com/julialang/original/3X/c/6/c6d1bf8035d2bfb4e3cb337a77f2cf505651407c.png)

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [January 30, 2020, 6:51pm UTC](https://discourse.julialang.org/t/how-do-you-create-a-transparent-png-using-images-jl/33981/4 "2020-01-30T18:51:15Z")

</div>

If the data appears to be correct in Julia, but wrong in the generated .png, that would seem to be a problem in ImageMagick.jl’s domain, so I’d start there. The fact that it seems to work on MacOS (which AFAIK uses QuartzImageIO instead of ImageMagick) also points in that direction.
