Sha256: a03b5511b5129c687ca52f7e10c67a87339a74eace26a4001d088be2f3cd496f

Contents?: true

Size: 881 Bytes

Versions: 5

Compression:

Stored size: 881 Bytes

Contents

class Face < Image
  # A user's "face" should be no bigger than 75x75.  So scale it with RMagick, if available
  begin 
    require 'RMagick'
    
    def before_save
      image = Magick::Image.read_inline(encode64(self.picture)).first
      image.change_geometry!('75x75') { |c,r,i| i.resize!(c, r) }
      self.height =  image.rows.to_s
      self.width  =  image.columns.to_s
      self.picture = image.to_blob
    end
  rescue LoadError
    # If RMagick isn't available, well, just dump the whole thing into the DB without scaling.
    # Too bad, so sorry.  Install RMagick or write us some pure Ruby to scale images :).
    require_dependency 'image_size'
    def before_save
      image = ImageSize.new(self.picture)
      ratio = 75.0 / image.get_width
      self.width  = (image.get_width * ratio).to_i
      self.height = (image.get_height * ratio).to_i
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
EliteJournal-1.9.400 app/models/face.rb
EliteJournal-1.9.401 app/models/face.rb
EliteJournal-1.9.403 app/models/face.rb
EliteJournal-1.9.480 app/models/face.rb
EliteJournal-1.9.492 app/models/face.rb