# RangeError (bignum too big to convert into \`long'

**URL:** <https://www.ruby-forum.com/t/rangeerror-bignum-too-big-to-convert-into-long/150407>\
**Category:** Rails\
**Created:** [October 8, 2008, 7:04am UTC](https://www.ruby-forum.com/t/rangeerror-bignum-too-big-to-convert-into-long/150407 "2008-10-08T07:04:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 8, 2008, 7:04am UTC](https://www.ruby-forum.com/t/rangeerror-bignum-too-big-to-convert-into-long/150407/1 "2008-10-08T07:04:53Z")

</div>

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’
