module Cloudimage::Srcset
Constants
- SRCSET_GROWTH_FACTOR
- SRCSET_RANGE
5760 is 3x 1920 (the largest common screen width): gs.statcounter.com/screen-resolution-stats
Public Instance Methods
to_srcset(**extra_params)
click to toggle source
# File lib/cloudimage/srcset.rb, line 10 def to_srcset(**extra_params) srcset_widths .map { |width| "#{to_url(**extra_params, w: width)} #{width}w" } .join(', ') end
Private Instance Methods
srcset_widths()
click to toggle source
# File lib/cloudimage/srcset.rb, line 18 def srcset_widths current = SRCSET_RANGE.begin [].tap do |widths| loop do widths << current current = (current * SRCSET_GROWTH_FACTOR).round(-1) break if current >= SRCSET_RANGE.end && widths << SRCSET_RANGE.end end end end