Module: PhotoCook::Resize::Calculations
- Defined in:
- lib/photo-cook/resize/calculations.rb
Class Method Summary collapse
- .round(x) ⇒ Object
- .size_to_fill(maxw, maxh, reqw, reqh, round = true) ⇒ Object
- .size_to_fit(maxw, maxh, reqw, reqh, round = true) ⇒ Object
Class Method Details
.round(x) ⇒ Object
54 55 56 |
# 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) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# 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 |