Class: Alula::Magick
Instance Attribute Summary
Attributes inherited from Processor
#attachments, #item, #options, #site
Instance Method Summary
collapse
#process, #sizes
Methods inherited from Processor
#asset_path, available?, #initialize, mimetype, #process, process?
Instance Method Details
#cleanup ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/alula/processors/magick.rb', line 38
def cleanup
super
@info = nil
@image = nil
@exif = nil
end
|
#exif ⇒ Object
56
57
58
|
# File 'lib/alula/processors/magick.rb', line 56
def exif
@exif ||= MiniExiftool.new self.item.filepath
end
|
#image ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/alula/processors/magick.rb', line 60
def image
@image ||= begin
image = ::Magick::Image.read(self.item.filepath).first
unless self.options[:no_rotate]
case image.orientation.to_i
when 2
image.flop!
when 3
image.rotate!(180)
when 4
image.flip!
when 5
image.transpose!
when 6
image.rotate!(90)
when 7
image.transverse!
when 8
image.rotate!(270)
end
image
end
end
end
|
#info ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/alula/processors/magick.rb', line 46
def info
@info ||= begin
info = ::Magick::Image.ping(self.item.filepath).first
Hashie::Mash.new({
width: info.columns,
height: info.rows,
})
end
end
|
#resize_image(opts) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/alula/processors/magick.rb', line 11
def resize_image(opts)
output = opts[:output]
width, height = opts[:size]
resize_mode = self.site.config.attachments.image["#{opts[:type]}_mode"]
resized = case resize_mode
when :square
self.image.resize_to_fill(width, height)
else
self.image.resize_to_fit(width, height)
end
resized.interlace = ::Magick::PlaneInterlace
tags = Hash[*(self.site.config.attachments["image"]["keep_tags"].collect{|t| [t, self.exif[t]]}).flatten]
resized.strip!
resized.write(output)
exif = MiniExiftool.new output
tags.each {|key, value| exif[key] = value }
exif.save
end
|