module PhotoCook::Resize::Calculations
Public Class Methods
round(x)
click to toggle source
# File lib/photo-cook/resize/calculations.rb, line 54 def round(x) PhotoCook::Pixels.round(x) end
size_to_fill(maxw, maxh, reqw, reqh, round = true)
click to toggle source
# File lib/photo-cook/resize/calculations.rb, line 20 def size_to_fill(maxw, maxh, reqw, reqh, round = true) outw, outh = reqw, reqh if reqw > maxw && reqh > maxh if maxw >= maxh outw = (reqw * maxh) / reqh.to_f outh = maxh if outw > maxw outh = (outh * maxw) / convert(outw) outw = maxw end else outw = maxw outh = (maxw * reqh) / reqw if outh > maxh outw = (outw * maxh) / convert(outh) outh = maxh end end elsif reqw > maxw outw = maxw outh = (reqh * maxw) / convert(reqw) elsif reqh > maxh outw = (reqw * maxh) / convert(reqh) outh = maxh end round ? [round(outw), round(outh)] : [outw, outh] end
size_to_fit(maxw, maxh, reqw, reqh, round = true)
click to toggle source
# File lib/photo-cook/resize/calculations.rb, line 8 def size_to_fit(maxw, maxh, reqw, reqh, round = true) outw, outh = maxw, maxh scale = outw > reqw ? reqw / convert(outw) : 1.0 outw, outh = outw * scale, outh * scale scale = outh > reqh ? reqh / convert(outh) : 1.0 outw, outh = outw * scale, outh * scale round ? [round(outw), round(outh)] : [outw, outh] end
Private Class Methods
convert(x)
click to toggle source
# File lib/photo-cook/resize/calculations.rb, line 59 def convert(x) x.kind_of?(Float) ? x : x.to_f end