question about transparent image RMAGIK

S

shawn bright

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
 
T

Tim Hunter

Shawn said:
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].

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] and
Draw#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].
 
S

shawn bright

fill_opacity was what i was looking for,
thanks very much.

shawn

Shawn said:
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].

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] and
Draw#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].
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top