SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ruby GD? Its acting oddly

    Hello again (as you can see from all the topics ive posted ive been getting pretty into rails ),

    Im in the process of converting my PHP application to Rails and its sooo much easier in Ruby But I hit a wall. I had a CAPTCHA image on the old [php powered] site and a quick google showed me that Ruby also had a GD extension. So I installed Ruby-GD and did a few tests to make sure it works alright, which it does.

    Then, I started converting my PHP code to Ruby line by line (for the captcha) and when I finished I crossed my fingers, refreshed, and was both happy and confused.

    I was happy because the image showed up somewhat correctly... there were no ruby errors. I was confused because now the words are all jumbled up (letters). So I looked over to make sure I copied it correctly, which i did.

    So now im wondering... is the Ruby-GD coordinate (x,y) system different from that of PHP? Or what differences are there in PHP's GD extension to Ruby's GD extension?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think the coordinate system is different, but I've had a similar problem. The problem was that Ruby does support integer division and PHP doesn't (PHP always returns a float), so maybe you need to do some explicit integer.to_f to get it right.

    Ruby:
    10 / 3 = 3

    PHP:
    10 / 3 = 3.3333333

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2
    I don't think the coordinate system is different, but I've had a similar problem. The problem was that Ruby does support integer division and PHP doesn't (PHP always returns a float), so maybe you need to do some explicit integer.to_f to get it right.

    Ruby:
    10 / 3 = 3

    PHP:
    10 / 3 = 3.3333333
    Hmm I'll check that out but even so the difference between the 2 above is .3... and that my images are off by like... 50 points. But we'll see. I'll check.

  4. #4
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2
    Ruby:
    10 / 3 = 3
    FWIW,

    Code:
    irb(main):001:0> 10/3
    => 3
    irb(main):002:0> 10.0/3
    => 3.33333333333333

    Douglas
    Hello World

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right.

    Integer/Integer = Integer
    Integer/Float = Float
    Float/Integer = Float
    Float/Float = Float


  6. #6
    Resident Java Hater
    Join Date
    Jul 2004
    Location
    Gerodieville Central, UK
    Posts
    446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Same rules apply here with dividing as to Java and C++, that's the easy way to remember.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •