Sha256: 63f64c3ea6b926f56ddee0c98db47ee5c473a54e76f0b7dc3a2ed5c52e59a11c
Contents?: true
Size: 1.12 KB
Versions: 15
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true module Decidim module Admin # This class contains helpers needed to obtain information about # image dimensions from the processors defined in the specific image's Uploader class module UploaderImageDimensionsHelper # 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] def image_dimensions(model, image_name) versions = model.send(image_name).dimensions_info [:small, :medium, :default].map { |v| versions.dig(v, :dimensions) }.compact.first end # Find the first value for the processed image width def image_width(model, image_name) image_dimensions(model, image_name)[0] end # Find the first value for the processed image height def image_height(model, image_name) image_dimensions(model, image_name)[1] end end end end
Version data entries
15 entries across 15 versions & 1 rubygems