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
37
|
# File 'lib/dragonfly_libvips/processors/thumb.rb', line 11
def call(content, geometry, options = {})
options = options.deep_stringify_keys
format = options.fetch('format', content.ext)
input_options = options.fetch('input_options', {})
resize_options = options.fetch('resize_options', {})
output_options = options.fetch('output_options', {})
input_options['access'] ||= 'sequential'
output_options['profile'] ||= DragonflyLibvips::EPROFILE_PATH
require 'vips'
img = ::Vips::Image.new_from_file(content.path, input_options)
dimensions = case geometry
when RESIZE_GEOMETRY then DragonflyLibvips::Dimensions.call(geometry, img.width, img.height)
else raise ArgumentError, "Didn't recognise the geometry string #{geometry}"
end
if dimensions.scale != 1
img = img.resize(dimensions.scale, resize_options)
end
content.update(img.write_to_buffer(".#{format}", output_options), 'format' => format)
content.ext = format
end
|