lib/remove_white_border.rb
# Determines and x and y that should be good to use for scanning the image.
Determines and x and y that should be good to use for scanning the image.
Determines and x and y that should be good to use for scanning the image .
def calculate_center(x = nil, y = nil, width = nil, height = nil)
      x      ||= @width / 2
      y      ||= @height / 2
      width  ||= @width
      height ||= @height
      return @coords if @coords
      return (@coords = [x, y]) if !white?(x, y)
      return if width <= 2 || height <= 2
      if coords = calculate_center(x - width/2, y - height/2, width/2, height/2)
        return coords
      end
      if coords = calculate_center(x - width/2, y + height/2, width/2, height/2)
        return coords
      end
      if coords = calculate_center(x + width/2, y - height/2, width/2, height/2)
        return coords
      end
      if coords = calculate_center(x + width/2, y + height/2, width/2, height/2)
        return coords
      end
    end
def calculate_center ( x = nil , y = nil , width = nil , height = nil ) x ||= @width / 2 y ||= @height / 2 width ||= @width height ||= @height return @coords if @coords return ( @coords = [ x , y ] ) if ! white? ( x , y ) return if width <= 2 || height <= 2 if coords = calculate_center ( x - width / 2 , y - height / 2 , width / 2 , height / 2 ) return coords end if coords = calculate_center ( x - width / 2 , y + height / 2 , width / 2 , height / 2 ) return coords end if coords = calculate_center ( x + width / 2 , y - height / 2 , width / 2 , height / 2 ) return coords end if coords = calculate_center ( x + width / 2 , y + height / 2 , width / 2 , height / 2 ) return coords end end
Determines and x and y that should be good to use for scanning the image.
Determines and x and y that should be good to use for scanning the image .
x
<not_specific>
y
<not_specific>
width
<not_specific>
height
<not_specific>