rmagick/rmagick — Issue #37: Opacity
Author: artimuz
Created: 2011-11-25 11:26:00+00:00
State: open

Hi,

I'm trying to convert a JPG to a PNG with a percentage of translucency. Here the code I've so far :

require 'RMagick'
image = Magick::Image.read(t.img.path).first
image.format = 'PNG'
image.background_color = 'none'
image.alpha(Magick::ActivateAlphaChannel)
image.matte = true
image.opacity = (Magick::TransparentOpacity - Magick::OpaqueOpacity) * (1.0 - alpha.to_f)

send_data image.to_blob,
:filename => "texture__#{params[:id]}_alpha_#{params[:alpha]}.png",
:disposition => 'inline',
:type => "image/png"

I tried all things : alpha, matte, ... Nothing to do, to_blob return each time the image with no translucency. When exploring the code, I've noted a comment (on the image_opacity exemple) : "Replace use of #opacity attribute (which doesn't seem to be working) … [rmagick]"