Forum: Ruby Transparent Image Using Rmagick

4087fa40d402c6418774c115347c1dd8?d=identicon&s=25 Radu Ciocan (ciocan)
on 2007-07-26 11:40
Hello,

I use rmagick to create a new image.
How can I make this image with 50% transparency?

Thanks
A8486651a974d7d9ecc35d25de96c7ee?d=identicon&s=25 Chris Lowis (chrislo)
on 2007-07-26 11:47
> I use rmagick to create a new image.
> How can I make this image with 50% transparency?

Take a look at the tutorials on the rmagick website (
http://rmagick.rubyforge.org/ ). This one features transparency/opacity
:

http://rmagick.rubyforge.org/Polaroid/polaroid.html

I don't use rmagick very much, but I found these by googling "rmagick
transparent".

Hope this helps,

Chris
4087fa40d402c6418774c115347c1dd8?d=identicon&s=25 Radu Ciocan (ciocan)
on 2007-07-26 12:06
I found here an example:
http://blog.corunet.com/english/the-definitive-heatmap
it works, but it use external ImageMagick convert program

@opacity = "0.50"
@path = './'
transparency = "convert "<<@path<<'image.png -channel A -fx
"A*'<<@opacity<<'"  '<<@path<<'image_transparent.png'
system(transparency)

How can I transform this in ruby rmagick code?


Chris Lowis wrote:
>> I use rmagick to create a new image.
>> How can I make this image with 50% transparency?
>
> Take a look at the tutorials on the rmagick website (
> http://rmagick.rubyforge.org/ ). This one features transparency/opacity
> :
>
> http://rmagick.rubyforge.org/Polaroid/polaroid.html
>
> I don't use rmagick very much, but I found these by googling "rmagick
> transparent".
>
> Hope this helps,
>
> Chris
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2007-07-26 13:24
(Received via mailing list)
Radu Ciocan wrote:
> Hello,
>
> I use rmagick to create a new image.
> How can I make this image with 50% transparency?
>
> Thanks
>
If you just want a solid-color image that's 50% transparent, specify the
color and transparency when you create the image:

img = Magick::Image.new(columns. rows) {self.background_color =
Magick::Pixel.new(rr, gg, bb, Magick::MaxRGB/2)}

where columns and rows specify the size of the image, and rr, gg, bb
specify the red, green, and blue channels.

If you have an image already and you want to change the opacity, use the
#opacity attribute:

img.opacity = Magick::MaxRGB / 2

http://www.simplesystems.org/RMagick/doc/imageattr...
http://www.simplesystems.org/RMagick/doc/struct.html#Pixel
http://www.simplesystems.org/RMagick/doc/image1.html#new
4087fa40d402c6418774c115347c1dd8?d=identicon&s=25 Radu Ciocan (ciocan)
on 2007-07-26 14:07
Thanks Tim for your reply.

My image is not with one solid color.
I have already an image to change the opacity.

Unfortunately, I tried
img.opacity = Magick::MaxRGB / 2
but it doesn't working

I tried also with background_color = 'none'.

Any clues?

Thanks

Tim Hunter wrote:
> Radu Ciocan wrote:
>> Hello,
>>
>> I use rmagick to create a new image.
>> How can I make this image with 50% transparency?
>>
>> Thanks
>>
> If you just want a solid-color image that's 50% transparent, specify the
> color and transparency when you create the image:
>
> img = Magick::Image.new(columns. rows) {self.background_color =
> Magick::Pixel.new(rr, gg, bb, Magick::MaxRGB/2)}
>
> where columns and rows specify the size of the image, and rr, gg, bb
> specify the red, green, and blue channels.
>
> If you have an image already and you want to change the opacity, use the
> #opacity attribute:
>
> img.opacity = Magick::MaxRGB / 2
>
> http://www.simplesystems.org/RMagick/doc/imageattr...
> http://www.simplesystems.org/RMagick/doc/struct.html#Pixel
> http://www.simplesystems.org/RMagick/doc/image1.html#new
B33ea5c12d767bfd1253940a960274f5?d=identicon&s=25 Tim Hunter (timhunter)
on 2007-07-26 14:32
(Received via mailing list)
On Jul 26, 8:07 am, Radu Ciocan <cio...@gmail.com> wrote:
>
>

What makes you think it doesn't work? How are you viewing the image?
What kind of image is it? A GIF? A JPEG?
4087fa40d402c6418774c115347c1dd8?d=identicon&s=25 Radu Ciocan (ciocan)
on 2007-07-26 14:43
Tim Hunter wrote:
> On Jul 26, 8:07 am, Radu Ciocan <cio...@gmail.com> wrote:
>>
>>
>
> What makes you think it doesn't work? How are you viewing the image?
> What kind of image is it? A GIF? A JPEG?

It's a png image.
The image generated with convert has opacity 50% (i viewed with acdsee)
The image generated with rmagick doesn't have opacity.
B33ea5c12d767bfd1253940a960274f5?d=identicon&s=25 Tim Hunter (timhunter)
on 2007-07-26 15:06
(Received via mailing list)
On Jul 26, 8:43 am, Radu Ciocan <cio...@gmail.com> wrote:
> --
> Posted viahttp://www.ruby-forum.com/.

Send the image and a script that reproduces the problem to rmagick AT
rubyforge DOT org and I'll take a look at it.
4087fa40d402c6418774c115347c1dd8?d=identicon&s=25 Radu Ciocan (ciocan)
on 2007-07-26 16:43
Tim Hunter wrote:
> On Jul 26, 8:43 am, Radu Ciocan <cio...@gmail.com> wrote:
>> --
>> Posted viahttp://www.ruby-forum.com/.
>
> Send the image and a script that reproduces the problem to rmagick AT
> rubyforge DOT org and I'll take a look at it.

Here is an example of script:

    require 'RMagick'
    image = Magick::Image.read('public/images/rails.png').first
    image.opacity = Magick::MaxRGB / 2
    image.write("public/images/rails_with_transparency.png")

(rails.png is the default rails logo from a new rails app)
theoretically, this should be working, but is not working,
the new image rails_with_transparency.png is the same as rails.png
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2007-07-26 23:32
(Received via mailing list)
Radu Ciocan wrote:
>
>
I didn't get any mail from you. Without the image I can't help you.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.