# Another RMagick and rotation question

**URL:** <https://www.ruby-forum.com/t/another-rmagick-and-rotation-question/129061>\
**Category:** Ruby\
**Created:** [February 13, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/another-rmagick-and-rotation-question/129061 "2008-02-13T22:27:32Z")\
**Posts on this page:** 5\
**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 13, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/another-rmagick-and-rotation-question/129061/1 "2008-02-13T22:27:32Z")

</div>

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

---

<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 14, 2008, 12:14am UTC](https://www.ruby-forum.com/t/another-rmagick-and-rotation-question/129061/2 "2008-02-14T00:14:04Z")

</div>

shawn bright wrote:

> 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?

---

<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 14, 2008, 12:47am UTC](https://www.ruby-forum.com/t/another-rmagick-and-rotation-question/129061/3 "2008-02-14T00:47:01Z")

</div>

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.

---

<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 14, 2008, 2:44am UTC](https://www.ruby-forum.com/t/another-rmagick-and-rotation-question/129061/4 "2008-02-14T02:44:19Z")

</div>

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?

---

<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 14, 2008, 3:27am UTC](https://www.ruby-forum.com/t/another-rmagick-and-rotation-question/129061/5 "2008-02-14T03:27:42Z")

</div>

ok, will do  
thanks
