another RMagick and rotation question

S

shawn bright

Hello there all,

i have an RMagick image of a circle with a line through it ( in png)
i would like to rotate the image, but whenever i use rotate to do
this, it makes a smaller image because the image is actually a cirlce
on a square transparent background.

It will not make the image smaller if it is rotated angles of 90, 180,
270 or 0 degrees, but as it approaches angles between those ( like 45
and so on) the image is smaller and smaller.

Has anyone got a good idea or workaround for this. I would love to
rotate the image but keep the circle part of the image the same size.

thanks for any tips

sk
 
T

Tim Hunter

shawn said:
Hello there all,

i have an RMagick image of a circle with a line through it ( in png)
i would like to rotate the image, but whenever i use rotate to do
this, it makes a smaller image because the image is actually a cirlce
on a square transparent background.

It will not make the image smaller if it is rotated angles of 90, 180,
270 or 0 degrees, but as it approaches angles between those ( like 45
and so on) the image is smaller and smaller.

Has anyone got a good idea or workaround for this. I would love to
rotate the image but keep the circle part of the image the same size.

thanks for any tips

sk


Can you post some code?
 
S

shawn bright

ok, here we go....

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('red')
gc.stroke_width(1)

# fill in the inside
gc.fill('red')
gc.fill_opacity(0.3)
gc.circle(r, r, 0, r)
image = gc.draw(canvas)

# place the line for gps
if site.has_gps_sensor?
# fetch the image of a line
gps_image = self.gps_image(site, r)
canvas.composite!(gps_image, 0, 0, Magick::OverCompositeOp)
angle = site.gps_sensor.projected_position # will be between 1
and 360 degrees
canvas.rotate!(angle)
end
end

then there is the code to canvas.write('image.png') or whatever.
Basic idea is to draw a circle, then draw the line from the center to
the edge of the circle, this is done with another image
that is just a line that gets superimposed over the circle image.

thanks so much for looking at this,.

sk

then it all gets rotated and that is where it gets shortened.
 
T

Tim Hunter

shawn said:
ok, here we go....

I'm sorry, Shawn. I'm too stupid too figure out what you're wanting to
do just from this. I tried to fill out the example but I get a
"undefined method `site'" message.

In general, the rotate method results in a larger image, not smaller.

Can you post a complete, working, example on the RMagick help forum on
RubyForge?
 
S

shawn bright

ok, will do
thanks

I'm sorry, Shawn. I'm too stupid too figure out what you're wanting to
do just from this. I tried to fill out the example but I get a
"undefined method `site'" message.

In general, the rotate method results in a larger image, not smaller.

Can you post a complete, working, example on the RMagick help forum on
RubyForge?
 

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,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top