Sha256: d9fd223ed2f967b43bfc04625ed70022d48648a57d3601af39ddc21dbc92cebb

Contents?: true

Size: 671 Bytes

Versions: 9

Compression:

Stored size: 671 Bytes

Contents

module Thredded
  class Image < ActiveRecord::Base
    mount_uploader :image, ImageUploader
    validates :image, presence: true
    before_validation :save_dimensions, :save_orientation, :save_position

    private

    def save_dimensions
      if image.path
        self.width = MiniMagick::Image.open(image.path)[:width]
        self.height = MiniMagick::Image.open(image.path)[:height]
      end
    end

    def save_orientation
      if image.path
        self.orientation = (height.to_i > width.to_i) ? 'portrait' : 'landscape'
      end
    end

    def save_position
      self.position = (self._index + 1) if self.new_record? and self._index
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
thredded-0.0.12 app/models/thredded/image.rb
thredded-0.0.10 app/models/thredded/image.rb
thredded-0.0.9 app/models/thredded/image.rb
thredded-0.0.8 app/models/thredded/image.rb
thredded-0.0.7 app/models/thredded/image.rb
thredded-0.0.6 app/models/thredded/image.rb
thredded-0.0.5 app/models/thredded/image.rb
thredded-0.0.4 app/models/thredded/image.rb
thredded-0.0.3 app/models/thredded/image.rb