module PhotoCook::Pixels
Constants
- MAX
Public Class Methods
check!(x, ensure_in_bounds = true)
click to toggle source
# File lib/photo-cook/pixels.rb, line 18 def check!(x, ensure_in_bounds = true) x = typecast(x) raise Invalid, x if !x.kind_of?(Integer) && (x.nan? || x.infinite?) raise OutOfBounds, x if ensure_in_bounds && !in_bounds?(x) true end
in_bounds?(x)
click to toggle source
# File lib/photo-cook/pixels.rb, line 25 def in_bounds?(x) x = typecast(x) 0 < x && x <= MAX end
parse(x)
click to toggle source
# File lib/photo-cook/pixels.rb, line 9 def parse(x) round(typecast(x)) end
parse!(x)
click to toggle source
# File lib/photo-cook/pixels.rb, line 13 def parse!(x) check!(x = parse(x)) x end
round(x)
click to toggle source
Standardize how dimensions are rounded in PhotoCook
# File lib/photo-cook/pixels.rb, line 31 def round(x) x.floor end
to_magick_dimensions(width, height)
click to toggle source
Returns Imagemagick dimension-string
# File lib/photo-cook/pixels.rb, line 36 def to_magick_dimensions(width, height) "#{width}x#{height}" end
typecast(x)
click to toggle source
# File lib/photo-cook/pixels.rb, line 40 def typecast(x) x.kind_of?(Numeric) ? x : x.to_f end