RMagick ignores opacity when creating a new image with RVG

I am trying to create an image with a transparent background, but not even creating an image that is just transparent png. I tried this:

require "rvg/rvg" rvg = Magick::RVG.new(100, 100) rvg.background_fill = "pink" # Shouldn't matter rvg.background_fill_opacity = 0 rvg.draw.write("transparent.png") 

which generates:

enter image description here

I also tried:

 rvg.background_fill.opacity = 0 rvg.styles(:fill_opacity => 0) rvg.styles(:opacity => 0) 

They all turned out to be a solid pink rectangle.

How to create transparent png using RMagick RVG?

Refresh : the image seems not even transparent:

 1.9.2p320 :007 > rvg.draw => transparent.png 100x100 DirectClass 8-bit 1.9.2p320 :008 > rvg.draw.alpha => false 1.9.2p320 :009 > rvg.draw.alpha? => false 
+4
source share
1 answer

Before rvg.image.write add this line:

rvg.draw.alpha (Magick :: ActivateAlphaChannel)

Then you do not need to set background_fill, and the resulting image will be a nice, smooth transparent image.

+1
source

All Articles