Last active
June 4, 2016 21:19
-
-
Save ibanez270dx/20122c7b6457b0c9833a0323b99d5fbb to your computer and use it in GitHub Desktop.
Helper for displaying an image using filestack.com and their conversion options
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
# Usage: | |
# <%= filestack_image_tag post.filestack_url, resize: { width: 100, height: 200, fit: crop }, oil_paint: { amount: 7 } %> | |
# | |
# => https://process.filestackapi.com/[FILESTACK API KEY]/resize=width:72,height:72,fit:crop/oil_paint=amount:7/https://cdn.filestackcontent.com/abc23... | |
def filestack_image_tag(url, task_options={}, image_tag_options={}) | |
base_path = "https://process.filestackapi.com/#{Rails.application.config.filestack_api_key}" | |
task_path = task_options.collect do |task, options| | |
"#{task.to_s}=#{options.collect{|k,v| "#{k}:#{v}"}.join(',')}" | |
end.join('/') | |
image_url = [base_path, task_path, url].join('/') | |
view_context.image_tag image_url, image_tag_options | |
end | |
helper_method :filestack_image_tag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment