Module: Inkfilepicker::ViewHelpers
- Defined in:
- lib/inkfilepicker/view_helpers.rb
Instance Method Summary collapse
-
#inkfilepicker_image_tag(url, image_options = {}, image_tag_options = {}) ⇒ Object
Allows options to be passed to inkfilepicker_image_url and then falls back to normal Rails options for image_tag If specifying html width, height, pass it down to inkfilepicker for optimization.
-
#inkfilepicker_image_url(url, options = {}) ⇒ Object
w - Resize the image to this width.
- #inkfilepicker_js_include_tag ⇒ Object
- #inkfilepicker_save_button(text, url, mimetype, options = {}) ⇒ Object
Instance Method Details
#inkfilepicker_image_tag(url, image_options = {}, image_tag_options = {}) ⇒ Object
Allows options to be passed to inkfilepicker_image_url and then falls back to normal Rails options for image_tag If specifying html width, height, pass it down to inkfilepicker for optimization
25 26 27 |
# File 'lib/inkfilepicker/view_helpers.rb', line 25 def inkfilepicker_image_tag(url, ={}, ={}) image_tag(inkfilepicker_image_url(url, ), ) end |
#inkfilepicker_image_url(url, options = {}) ⇒ Object
w - Resize the image to this width.
h - Resize the image to this height.
fit - Specifies how to resize the image. Possible values are:
clip: Resizes the image to fit within the specified parameters without
distorting, cropping, or changing the aspect ratio
crop: Resizes the image to fit the specified parameters exactly by
removing any parts of the image that don't fit within the boundaries
scales: Resizes the image to fit the specified parameters exactly by
scaling the image to the desired size
Defaults to "clip".
align - Determines how the image is aligned when resizing and using the “fit” parameter. Check API for details.
cache - Specifies if the image should be cached or not.
crop - Crops the image to a specified rectangle. The input to this parameter
should be 4 numbers for 'x,y,width,height' - for example,
'crop=10,20,200,250' would select the 200x250 pixel rectangle starting
from 10 pixels from the left edge and 20 pixels from the top edge of the
image.
format - Specifies what format the image should be converted to, if any.
Possible values are "jpg" and "png". For "jpg" conversions, you
can additionally specify a quality parameter.
quality - For jpeg conversion, specifies the quality of the resultant image.
Quality should be an integer between 1 and 100
watermark - Adds the specified absolute url as a watermark on the image.
watersize - This size of the watermark, as a percentage of the base
image (not the original watermark).
waterposition - Where to put the watermark relative to the base image.
Possible values for vertical position are "top","middle",
"bottom" and "left","center","right", for horizontal
position. The two can be combined by separating vertical
and horizontal with a comma. The default behavior
is bottom,right
69 70 71 72 |
# File 'lib/inkfilepicker/view_helpers.rb', line 69 def inkfilepicker_image_url(url, = {}) query_params = .slice(:w, :h, :fit, :align, :cache, :crop, :format, :quality, :watermark, :watersize, :waterposition).to_query [url, "/convert?", query_params].join end |
#inkfilepicker_js_include_tag ⇒ Object
4 5 6 |
# File 'lib/inkfilepicker/view_helpers.rb', line 4 def inkfilepicker_js_include_tag javascript_include_tag "#{Inkfilepicker.api_url}" end |
#inkfilepicker_save_button(text, url, mimetype, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/inkfilepicker/view_helpers.rb', line 8 def (text, url, mimetype, = {}) [:data] ||= {} container = .delete(:container) services = .delete(:services) save_as = .delete(:save_as_name) [:data]['fp-url'] = url [:data]['fp-apikey'] = Inkfilepicker.api_key [:data]['fp-mimetype'] = mimetype [:data]['fp-option-container'] = container if container [:data]['fp-option-services'] = Array(services).join(",") if services [:data]['fp-option-defaultSaveasName'] = save_as if save_as (text, ) end |