Module: Decidim::Admin::UploaderImageDimensionsHelper

Defined in:
decidim-admin/app/helpers/decidim/admin/uploader_image_dimensions_helper.rb

Overview

This class contains helpers needed to obtain information about image dimensions from the processors defined in the specific image’s Uploader class

Instance Method Summary collapse

Instance Method Details

#image_dimensions(model, image_name) ⇒ Object

Find the dimensions info of a model’s image field and get the first value for dimensions ([w, h])

model - The model to which the image belongs (An instance of ‘ActiveRecord`) image_name - The attribute name for the image (either a `symbol` or a `string`)

Returns an integer array with [width, height]



14
15
16
17
18
# File 'decidim-admin/app/helpers/decidim/admin/uploader_image_dimensions_helper.rb', line 14

def image_dimensions(model, image_name)
  uploader = model.attached_uploader(image_name) || model.send(image_name)
  versions = uploader.dimensions_info
  [:small, :medium, :default].map { |v| versions.dig(v, :dimensions) }.compact.first
end

#image_height(model, image_name) ⇒ Object

Find the first value for the processed image height



26
27
28
# File 'decidim-admin/app/helpers/decidim/admin/uploader_image_dimensions_helper.rb', line 26

def image_height(model, image_name)
  image_dimensions(model, image_name)[1]
end

#image_width(model, image_name) ⇒ Object

Find the first value for the processed image width



21
22
23
# File 'decidim-admin/app/helpers/decidim/admin/uploader_image_dimensions_helper.rb', line 21

def image_width(model, image_name)
  image_dimensions(model, image_name)[0]
end