Sha256: 54c998772050928b5d921ba7f5b7797e3c375c9f20b4dcae329ab5e8867fe69e

Contents?: true

Size: 1.28 KB

Versions: 40

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Alchemy
  class Picture < BaseRecord
    module Calculations
      # An Image smaller than dimensions
      # can not be cropped to given size - unless upsample is true.
      #
      def can_be_cropped_to?(string, upsample = false)
        return true if upsample

        is_bigger_than? sizes_from_string(string)
      end

      # Returns true if both dimensions of the base image are bigger than the dimensions hash.
      #
      def is_bigger_than?(dimensions)
        image_file_width > dimensions[:width] && image_file_height > dimensions[:height]
      end

      # Returns true is one dimension of the base image is smaller than the dimensions hash.
      #
      def is_smaller_than?(dimensions)
        !is_bigger_than?(dimensions)
      end

      # Given a string with an x, this function returns a Hash with point
      # :width and :height.
      #
      def sizes_from_string(string)
        width, height = string.to_s.split("x", 2).map(&:to_i)

        {
          width: width,
          height: height,
        }
      end

      # This function returns the :width and :height of the image file
      # as a Hash
      def image_size
        {
          width: image_file_width,
          height: image_file_height,
        }
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
alchemy_cms-6.1.10 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.9 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.8 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.7 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.6 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.5 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.0.14 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.4 app/models/alchemy/picture/calculations.rb
alchemy_cms-7.0.0.pre.a app/models/alchemy/picture/calculations.rb
alchemy_cms-6.0.13 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.3 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.2 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.1 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.1.0 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.0.12 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.0.11 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.0.10 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.0.9 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.0.8 app/models/alchemy/picture/calculations.rb
alchemy_cms-6.0.7 app/models/alchemy/picture/calculations.rb