8
9
10
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
38
39
40
|
# File 'lib/dragonfly_libvips/processors/extract_area.rb', line 8
def call(content, x, y, width, height, options = {})
raise UnsupportedFormat unless content.ext
raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)
options = DragonflyLibvips.stringify_keys(options)
format = options.fetch("format", content.ext)
input_options = options.fetch("input_options", {})
if content.mime_type == "image/jpeg"
input_options["autorotate"] = true unless input_options.has_key?("autorotate")
end
output_options = options.fetch("output_options", {})
if FORMATS_WITHOUT_PROFILE_SUPPORT.include?(format)
output_options.delete("profile")
else
output_options["profile"] ||= input_options.fetch("profile", EPROFILE_PATH)
end
output_options.delete("Q") unless /jpg|jpeg/i.match?(format.to_s)
output_options["format"] ||= format.to_s if /gif|bmp/i.match?(format.to_s)
img = ::Vips::Image.new_from_file(content.path, **DragonflyLibvips.symbolize_keys(input_options))
img = img.(x, y, width, height)
content.update(
img.write_to_buffer(".#{format}", **DragonflyLibvips.symbolize_keys(output_options)),
"name" => "temp.#{format}",
"format" => format
)
content.ext = format
end
|