Module: DynamicImage::Helper
- Defined in:
- lib/dynamic_image/helper.rb
Overview
DynamicImage Helper
Provides helper methods for rendering and linking to images.
Instance Method Summary collapse
-
#download_dynamic_image_path(record_or_array, options = {}) ⇒ Object
Returns a path to the original uploaded file for download, without any processing applied.
-
#download_dynamic_image_url(record_or_array, options = {}) ⇒ Object
Returns a URL to the original uploaded file for download, without any processing applied.
-
#dynamic_image_path(record_or_array, options = {}) ⇒ Object
Returns the path for a DynamicImage::Model record.
-
#dynamic_image_tag(record_or_array, options = {}) ⇒ Object
Returns an HTML image tag for the record.
-
#dynamic_image_url(record_or_array, options = {}) ⇒ Object
Returns the URL for a DynamicImage::Model record.
-
#original_dynamic_image_path(record_or_array, options = {}) ⇒ Object
Returns a path to the original uploaded file, without any processing applied.
-
#original_dynamic_image_url(record_or_array, options = {}) ⇒ Object
Returns a URL to the original uploaded file, without any processing applied.
-
#uncropped_dynamic_image_path(record_or_array, options = {}) ⇒ Object
Same as
dynamic_image_path
, but points to an image with any pre-cropping disabled. -
#uncropped_dynamic_image_tag(record_or_array, options = {}) ⇒ Object
Same as
dynamic_image_tag
, but renders an image with any pre-cropping disabled. -
#uncropped_dynamic_image_url(record_or_array, options = {}) ⇒ Object
Same as
dynamic_image_url
, but points to an image with any pre-cropping disabled.
Instance Method Details
#download_dynamic_image_path(record_or_array, options = {}) ⇒ Object
Returns a path to the original uploaded file for download, without any processing applied. Sizing options are not supported.
73 74 75 |
# File 'lib/dynamic_image/helper.rb', line 73 def download_dynamic_image_path(record_or_array, = {}) dynamic_image_path(record_or_array, { action: :download }.merge()) end |
#download_dynamic_image_url(record_or_array, options = {}) ⇒ Object
Returns a URL to the original uploaded file for download, without any processing applied. Sizing options are not supported.
80 81 82 |
# File 'lib/dynamic_image/helper.rb', line 80 def download_dynamic_image_url(record_or_array, = {}) dynamic_image_url(record_or_array, { action: :download }.merge()) end |
#dynamic_image_path(record_or_array, options = {}) ⇒ Object
Returns the path for a DynamicImage::Model record. Takes the same options as dynamic_image_url
10 11 12 |
# File 'lib/dynamic_image/helper.rb', line 10 def dynamic_image_path(record_or_array, = {}) dynamic_image_url(record_or_array, { routing_type: :path }.merge()) end |
#dynamic_image_tag(record_or_array, options = {}) ⇒ Object
Returns an HTML image tag for the record. If no size is given, it will render at the original size.
Options
-
:alt
: If no alt text is given, it will default to the filename of the uploaded image.
See dynamic_image_url
for info on how to size and cropping. Options supported by polymorphic_url
will be passed to the router. Any other options will be added as HTML attributes.
Examples
image = Image.find(params[:id])
dynamic_image_tag(image)
# => <img height="200" src="..." width="320" />
dynamic_image_tag(image, size: "100x100", alt="Avatar")
# => <img alt="Avatar" height="62" src="..." width="100" />
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dynamic_image/helper.rb', line 32 def dynamic_image_tag(record_or_array, = {}) size = fit_size!(record_or_array, ) = .extract!(*) = { size: }.merge() image_tag(dynamic_image_path_with_size(record_or_array, size, ), ) end |
#dynamic_image_url(record_or_array, options = {}) ⇒ Object
Returns the URL for a DynamicImage::Model record.
Options
-
:size
- Desired image size, supplied as “widthxheight”. The image will be scaled to fit. A partial size like “100x” or “x100” can be given, if you want a fixed width or height. -
:crop
- If true, the image will be cropped to the given size. -
:upscale
- By default, DynamicImage only scale images down, never up. Passupscale: true
to force upscaling.
Any options supported by polymorphic_url
are also accepted.
Examples
image = Image.find(params[:id])
dynamic_image_url(image)
# => "http://example.com/images/96...d1/300x187/1-2014062020...00.jpg"
dynamic_image_url(image, size: '100x100')
# => "http://example.com/images/72...c2/100x62/1-2014062020...00.jpg"
dynamic_image_url(image, size: '100x100', crop: true)
# => "http://example.com/images/a4...6b/100x100/1-2014062020...00.jpg"
65 66 67 68 |
# File 'lib/dynamic_image/helper.rb', line 65 def dynamic_image_url(record_or_array, = {}) size = fit_size!(record_or_array, ) dynamic_image_url_with_size(record_or_array, size, ) end |
#original_dynamic_image_path(record_or_array, options = {}) ⇒ Object
Returns a path to the original uploaded file, without any processing applied. Sizing options are not supported.
86 87 88 |
# File 'lib/dynamic_image/helper.rb', line 86 def original_dynamic_image_path(record_or_array, = {}) dynamic_image_path(record_or_array, { action: :original }.merge()) end |
#original_dynamic_image_url(record_or_array, options = {}) ⇒ Object
Returns a URL to the original uploaded file, without any processing applied. Sizing options are not supported.
92 93 94 |
# File 'lib/dynamic_image/helper.rb', line 92 def original_dynamic_image_url(record_or_array, = {}) dynamic_image_url(record_or_array, { action: :original }.merge()) end |
#uncropped_dynamic_image_path(record_or_array, options = {}) ⇒ Object
Same as dynamic_image_path
, but points to an image with any pre-cropping disabled.
98 99 100 |
# File 'lib/dynamic_image/helper.rb', line 98 def uncropped_dynamic_image_path(record_or_array, = {}) dynamic_image_path(record_or_array, { action: :uncropped }.merge()) end |
#uncropped_dynamic_image_tag(record_or_array, options = {}) ⇒ Object
Same as dynamic_image_tag
, but renders an image with any pre-cropping disabled.
104 105 106 |
# File 'lib/dynamic_image/helper.rb', line 104 def uncropped_dynamic_image_tag(record_or_array, = {}) dynamic_image_tag(record_or_array, { action: :uncropped }.merge()) end |
#uncropped_dynamic_image_url(record_or_array, options = {}) ⇒ Object
Same as dynamic_image_url
, but points to an image with any pre-cropping disabled.
110 111 112 |
# File 'lib/dynamic_image/helper.rb', line 110 def uncropped_dynamic_image_url(record_or_array, = {}) dynamic_image_url(record_or_array, { action: :uncropped }.merge()) end |