RangeError (bignum too big to convert into `long'


#1

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 = (picwidthpercentcrop) #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:incrop’
/app/controllers/crop_controller.rb:98:in topcrop' /app/controllers/crop_controller.rb:233:inupdownevent’
/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:insend’
/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:incall_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:inperform_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:inperform_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’