Last active
May 19, 2016 11:00
-
-
Save samrayner/cf6b535b2234b75b37bd2382d4c139be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# image_uploader.rb | |
version :small_3x do process resize_to_limit: [900, 900] end | |
version :small_2x, from_version: :small_3x do process resize_to_limit: [600, 600] end | |
version :small, from_version: :small_2x do process resize_to_limit: [300, 300] end | |
version :thumb_3x, from_version: :small do process resize_to_limit: [150, 150] end | |
version :thumb_2x, from_version: :thumb_3x do process resize_to_limit: [100, 100] end | |
version :thumb, from_version: :thumb_2x do process resize_to_limit: [50, 50] end | |
# application_helper.rb | |
def retina_image_tag(uploader, version, options={}) | |
options.symbolize_keys! | |
fallback = options.delete(:fallback) | |
return image_tag(fallback, options) unless uploader | |
options[:srcset] ||= (2..3).map do |multiplier| | |
name = "#{version}_#{multiplier}x" | |
if uploader.version_exists?(name) && source = uploader.url(name).presence | |
"#{source} #{multiplier}x" | |
else | |
nil | |
end | |
end.compact.join(', ') | |
image_tag(uploader.url(version).presence || fallback, options) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment