[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

another RMagick and rotation question

shawn bright

2/13/2008 9:26:00 PM

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

4 Answers

Tim Hunter

2/13/2008 11:11:00 PM

0

shawn bright wrote:
> 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?

--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

shawn bright

2/13/2008 11:46:00 PM

0

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.

On Feb 13, 2008 5:11 PM, Tim Hunter <TimHunter@nc.rr.com> wrote:
> shawn bright wrote:
> > 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?
>
> --
> RMagick: http://rmagick.ruby...
> RMagick 2: http://rmagick.ruby...rmagick2.html
>
>

Tim Hunter

2/14/2008 1:44:00 AM

0

shawn bright wrote:
> 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?

--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

shawn bright

2/14/2008 2:27:00 AM

0

ok, will do
thanks

On Feb 13, 2008 7:43 PM, Tim Hunter <TimHunter@nc.rr.com> wrote:
> shawn bright wrote:
> > 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?
>
> --
> RMagick: http://rmagick.ruby...
> RMagick 2: http://rmagick.ruby...rmagick2.html
>
>