Sha256: b800f65b7cabf034028d3df6bfcb7cec5d9aae6a208df3552e64206d2d24075d

Contents?: true

Size: 1.19 KB

Versions: 44

Compression:

Stored size: 1.19 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)
        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

      # 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

44 entries across 44 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.28.4 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.27.9 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.29.0 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.28.3 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.27.8 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.29.0.rc4 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.29.0.rc3 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.29.0.rc2 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.29.0.rc1 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.28.2 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.27.7 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.28.1 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.27.6 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.26.10 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.26.9 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.28.0 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.27.5 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.28.0.rc5 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb
decidim-admin-0.28.0.rc4 app/helpers/decidim/admin/uploader_image_dimensions_helper.rb