Class: Binda::Image

Inherits:
Asset show all
Defined in:
app/models/binda/image.rb

Overview

This class provides support for uploading images.

Defined Under Namespace

Classes: ImageUploader

Instance Method Summary collapse

Instance Method Details

#register_detailsObject

Register image details

Do not delete. This method is used by a rake task



10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/binda/image.rb', line 10

def register_details
  if !self.image.present?
    warn "Ops, there is no image for Binda::Image id=#{self.id}"
  elsif CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
    file = MiniMagick::Image.open(::Rails.root.join(self.image.path))
    register_details_of(file)
  else
    file = MiniMagick::Image.open(self.image.url)
    register_details_of(file)
  end
end

#register_details_of(file) ⇒ Object

Register image details

This method is used by register_details in a rake task



25
26
27
28
29
30
31
32
# File 'app/models/binda/image.rb', line 25

def register_details_of(file)
  self.file_width = file.width
  self.file_height = file.height
  self.content_type = file.mime_type if file.mime_type
  self.file_size = file.size
  self.save!
  puts "Updated image details for Binda::Image id=#{self.id}"
end