Module: Alchemy::Picture::Url

Includes:
Logger
Included in:
Alchemy::Picture
Defined in:
app/models/alchemy/picture/url.rb

Constant Summary collapse

TRANSFORMATION_OPTIONS =
[
  :crop,
  :crop_from,
  :crop_size,
  :flatten,
  :format,
  :quality,
  :size,
  :upsample
]

Instance Method Summary collapse

Methods included from Logger

#log_warning, warn

Instance Method Details

#url(options = {}) ⇒ Object

Returns a path to picture for use inside a image_tag helper.

Any additional options are passed to the url_helper, so you can add arguments to your url.

Example:

<%= image_tag picture.url(size: '320x200', format: 'png') %>


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/alchemy/picture/url.rb', line 26

def url(options = {})
  image = image_file

  raise MissingImageFileError, "Missing image file for #{inspect}" if image.nil?

  image = processed_image(image, options)
  image = encoded_image(image, options)

  image.url(options.except(*TRANSFORMATION_OPTIONS).merge(name: name))
rescue MissingImageFileError, WrongImageFormatError => e
  log_warning e.message
  nil
end