Class: LaserBlob::Blob::Image
Instance Attribute Summary
#data
Class Method Summary
collapse
Instance Method Summary
collapse
#extension, #file, #file=, new, #open, #url, #url=
#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.metadata = {
'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_ratio ⇒ Object
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_color ⇒ Object
17
18
19
|
# File 'app/models/laserblob/blob/image.rb', line 17
def background_color
metadata['background_color']
end
|
#dominant_color ⇒ Object
13
14
15
|
# File 'app/models/laserblob/blob/image.rb', line 13
def dominant_color
metadata['dominant_color']
end
|
#height ⇒ Object
9
10
11
|
# File 'app/models/laserblob/blob/image.rb', line 9
def height
metadata['height']
end
|
#width ⇒ Object
5
6
7
|
# File 'app/models/laserblob/blob/image.rb', line 5
def width
metadata['width']
end
|