# Question about transparent image RMAGIK

**URL:** <https://www.ruby-forum.com/t/question-about-transparent-image-rmagik/128301>\
**Category:** Ruby\
**Created:** [February 6, 2008, 4:11pm UTC](https://www.ruby-forum.com/t/question-about-transparent-image-rmagik/128301 "2008-02-06T16:11:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [February 6, 2008, 4:11pm UTC](https://www.ruby-forum.com/t/question-about-transparent-image-rmagik/128301/1 "2008-02-06T16:11:33Z")

</div>

Hello there all,  
i have a simple function to draw an image, but i cannot for the life  
of me figgure out from the docs how to make it about 20% transparent.

def circle\_image(zoom)  
site = self.site  
zoomhash = {13 =\> 0.5, 14 =\> 1, 15 =\> 2, 16 =\> 4}  
r = (self.radius.to\_f \* zoomhash[zoom.to\_i].to\_f)  
canvas = Magick::Image.new((2 \* r), (2\*r),  
Magick::HatchFill.new(‘transparent’, ‘transparent’))  
gc = Magick::Draw.new  
# for the outside perimeter of the circle  
gc.stroke(‘black’)  
gc.stroke\_width(1)  
# fill in the inside  
color = KeyWord.stat\_description(site.status\_sensor.last\_value)[1]  
gc.fill(color)  
gc.circle(r, r, 0, r)  
image = gc.draw(canvas)  
canvas.write(“public/images/tmp/#{site.id}.png”)  
end

please help, thanks

shawn

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [February 6, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/question-about-transparent-image-rmagik/128301/2 "2008-02-06T16:27:34Z")

</div>

Shawn B. wrote:

> Hello there all,  
> i have a simple function to draw an image, but i cannot for the life  
> of me figgure out from the docs how to make it about 20% transparent.
> 
> def circle\_image(zoom)  
> site = self.site  
> zoomhash = {13 =\> 0.5, 14 =\> 1, 15 =\> 2, 16 =\> 4}  
> r = (self.radius.to\_f \* zoomhash[zoom.to\_i].to\_f)  
> canvas = Magick::Image.new((2 \* r), (2\*r),  
> Magick::HatchFill.new(‘transparent’, ‘transparent’))  
> gc = Magick::Draw.new  
> # for the outside perimeter of the circle  
> gc.stroke(‘black’)  
> gc.stroke\_width(1)  
> # fill in the inside  
> color = KeyWord.stat\_description(site.status\_sensor.last\_value)[1]  
> gc.fill(color)  
> gc.circle(r, r, 0, r)  
> image = gc.draw(canvas)  
> canvas.write(“public/images/tmp/#{site.id}.png”)  
> end
> 
> please help, thanks
> 
> shawn

Do you want to make the entire image 20% transparent? Use the  
Image#opacity= attribute  
[[http://studio.imagemagick.org/RMagick/doc/imageattrs.html#opacity](http://studio.imagemagick.org/RMagick/doc/imageattrs.html#opacity)].

Do you want to make the drawing 20% transparent so that the drawn-upon  
image shows through? See the Draw#stroke\_opacity  
[[http://studio.imagemagick.org/RMagick/doc/draw.html#stroke\_opacity](http://studio.imagemagick.org/RMagick/doc/draw.html#stroke_opacity)] and  
Draw#fill\_opacity  
[[http://studio.imagemagick.org/RMagick/doc/draw.html#fill\_opacity](http://studio.imagemagick.org/RMagick/doc/draw.html#fill_opacity)]  
methods.

Also check out the example drawing here  
[[http://studio.imagemagick.org/RMagick/doc/usage.html#drawing\_on](http://studio.imagemagick.org/RMagick/doc/usage.html#drawing_on)].

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [February 6, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/question-about-transparent-image-rmagik/128301/3 "2008-02-06T17:18:28Z")

</div>

fill\_opacity was what i was looking for,  
thanks very much.

shawn
