RMagick transparency does not work when composing one image on top of another

In the following code, I am trying to impose a transparent square on the image of some mountains. I thought this would work, but setting background_color = 'none' will not make the image transparent!

The result is a black square in the upper left corner - the desired result - the black square should be transparent.

require 'open-uri' require 'RMagick' image_url = 'http://farm9.staticflickr.com/8446/7937080514_62d7749860.jpg' bg = Magick::ImageList.new open(image_url, 'rb') do |f| bg.from_blob(f.read) end layer = Magick::Image.new(200, 200) { self.background_color = 'none' } bg.each do |frame| frame.composite!(layer, 0, 0, Magick::OverCompositeOp) frame.strip! end bg.write('out.jpg') 

Here is my output image:

output with none transparent black square

Edit: I'm on Mac, Lion, ruby ​​1.9.3p125, ImageMagick 6.7.5-7

Edit 2: This works great on Heroku! But not in my car. Heroku has the same version of ImageMagick. Strange: |

+4
source share
1 answer

For some reason layer.alpha? == false layer.alpha? == false . So, I did sq.alpha(Magick::ActivateAlphaChannel) and then it will work!

Link: http://www.imagemagick.org/RMagick/doc/image1.html#alpha

+2
source

Source: https://habr.com/ru/post/1432511/


All Articles