Created
July 26, 2012 18:06
-
-
Save r38y/3183563 to your computer and use it in GitHub Desktop.
Ruby ResizeIO Client
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
module ResizeioHelper | |
def resizeio_image_tag(original, options={}) | |
rio_options = extract_resizeio_options(options) | |
image_tag resizeio_url(original, rio_options), options | |
end | |
def extract_resizeio_options(options) | |
retina = !!options.delete(:retina) | |
multiplier = retina ? 2 : 1 | |
transformation = options.delete(:t) || options.delete(:transformation) | |
rio_options = {} | |
rio_options[:t] = transformation if transformation | |
rio_options[:w] = options[:width] if options[:width] | |
rio_options[:h] = options[:height] if options[:height] | |
rio_options[:m] = multiplier | |
rio_options | |
end | |
def resizeio_url(original, params={}) | |
url = URI original | |
url.host = CONFIG.resizeio_host | |
url.query = params.to_query | |
url.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment