Class: LaserBlob::Blob::Image

Inherits:
LaserBlob::Blob show all
Defined in:
app/models/laserblob/blob/image.rb

Instance Attribute Summary

Attributes inherited from LaserBlob::Blob

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LaserBlob::Blob

#extension, #file, #file=, new, #open, #url, #url=

Methods included from LaserBlob::BlobHelpers

#file_content_type, #file_sha1, filename_from_file

Class Method Details

.process(record, path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/laserblob/blob/image.rb', line 26

def self.process(record, path)
  require 'vips' unless defined?(Vips)

  vips = Vips::Image.new_from_file(path)
  record. = {
    'width' =>      vips.width,
    'height' =>     vips.height,
    'dominant_color' => vips.thumbnail_image(1).getpoint(0, 0).join(","),
    'background_color' => vips.getpoint(0,0).join(",")
  }
end

Instance Method Details

#aspect_ratioObject



21
22
23
24
# File 'app/models/laserblob/blob/image.rb', line 21

def aspect_ratio
  return nil unless self.width && self.height
  self.width.to_f / self.height.to_f
end

#background_colorObject



17
18
19
# File 'app/models/laserblob/blob/image.rb', line 17

def background_color
  ['background_color']
end

#dominant_colorObject



13
14
15
# File 'app/models/laserblob/blob/image.rb', line 13

def dominant_color
  ['dominant_color']
end

#heightObject



9
10
11
# File 'app/models/laserblob/blob/image.rb', line 9

def height
  ['height']
end

#widthObject



5
6
7
# File 'app/models/laserblob/blob/image.rb', line 5

def width
  ['width']
end