Forum: Ruby on Rails RangeError (bignum too big to convert into `long'

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2008-10-08 09:04
(Received via mailing list)
I have written the following function in RoR for my website . The
function on execution gives an error for the Rmagick crop method , the
error is wriiten after the function . I am using the same
function(except for the change in name, rest everything is same) for
cropping from left , right and bottom and they are working fine.
All the left , right , top and bottomcrop functions are given the same
arguments but in case of topcrop these give an error and rest they
work fine .

FUNCTION:

def topcrop(path,cropfile,percentcrop)
path = path.chomp
cropfile = cropfile.chomp
percentcrop = (100-percentcrop.to_i)/100.0
picwidth = 640 ; #width of the pic (in pixels)
picheight = 480; #height of the pic (pixels)
widthchanged = (picwidth*percentcrop) #new width (based on the
percentage specified by the user)
heightchanged = (picheight*percentcrop) #new height (based on the
percentage of cropping specified by the user)
img = Magick::Image.read(path).first #reads the image specfied by the
user path
img = img.scale(640,480) #scales image to 640x480
img.write"/home/anmol/image.jpg" #scales image to 640x480
img.crop(SouthEastGravity,picwidth,heightchanged).write(cropfile)
end

ERROR :

RangeError (bignum too big to convert into `long'):
/app/controllers/crop_controller.rb:98:in `crop'
/app/controllers/crop_controller.rb:98:in `topcrop'
/app/controllers/crop_controller.rb:233:in `updownevent'
/app/controllers/application.rb:74:in `up'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
action_controller/bas
e.rb:1166:in `send'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
action_controller/bas
e.rb:1166:in `perform_action_without_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
action_controller/fil
ters.rb:579:in `call_filters'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
action_controller/fil
ters.rb:572:in `perform_action_without_benchmark'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
action_controller/ben
chmarking.rb:68:in `perform_action_without_rescue'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
action_controller/ben
chmarking.rb:68:in `perform_action_without_rescue'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/
action_controller/res
cue.rb:201:in `perform_action_without_caching'
This topic is locked and can not be replied to.