another RMagick and rotation question

Discussion in 'Ruby' started by shawn bright, Feb 13, 2008.

  1. shawn bright

    shawn bright Guest

    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
     
    shawn bright, Feb 13, 2008
    #1
    1. Advertising

  2. shawn bright

    Tim Hunter Guest

    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.rubyforge.org/
    RMagick 2: http://rmagick.rubyforge.org/rmagick2.html
     
    Tim Hunter, Feb 13, 2008
    #2
    1. Advertising

  3. shawn bright

    shawn bright Guest

    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 <> 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.rubyforge.org/
    > RMagick 2: http://rmagick.rubyforge.org/rmagick2.html
    >
    >
     
    shawn bright, Feb 13, 2008
    #3
  4. shawn bright

    Tim Hunter Guest

    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.rubyforge.org/
    RMagick 2: http://rmagick.rubyforge.org/rmagick2.html
     
    Tim Hunter, Feb 14, 2008
    #4
  5. shawn bright

    shawn bright Guest

    ok, will do
    thanks

    On Feb 13, 2008 7:43 PM, Tim Hunter <> 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.rubyforge.org/
    > RMagick 2: http://rmagick.rubyforge.org/rmagick2.html
    >
    >
     
    shawn bright, Feb 14, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hilz
    Replies:
    2
    Views:
    1,337
  2. Patrick

    Simple Rotation and bitmasking problem

    Patrick, Jul 19, 2007, in forum: C Programming
    Replies:
    1
    Views:
    373
    Old Wolf
    Jul 20, 2007
  3. fulio pen

    Rotation on FF and IE

    fulio pen, May 4, 2011, in forum: HTML
    Replies:
    2
    Views:
    836
    fulio pen
    May 4, 2011
  4. Pito Salas
    Replies:
    1
    Views:
    159
    Tim Hunter
    Apr 24, 2009
  5. Kevin

    Img rotation script question

    Kevin, Jan 1, 2004, in forum: Javascript
    Replies:
    1
    Views:
    115
    Kevin
    Jan 3, 2004
Loading...

Share This Page