lib/dragonfly_libvips/processors/rotate.rb in dragonfly_libvips-2.3.1 vs lib/dragonfly_libvips/processors/rotate.rb in dragonfly_libvips-2.3.2
- old
+ new
@@ -1,5 +1,7 @@
+require 'vips'
+
module DragonflyLibvips
module Processors
class Rotate
def call(content, rotate, options = {})
raise UnsupportedFormat unless content.ext
@@ -7,20 +9,25 @@
options = options.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v } # stringify keys
format = options.fetch('format', content.ext)
input_options = options.fetch('input_options', {})
- output_options = options.fetch('output_options', {})
# input_options['access'] ||= 'sequential'
if content.mime_type == 'image/jpeg'
input_options['autorotate'] = true unless input_options.has_key?('autorotate')
end
- output_options['profile'] ||= EPROFILE_PATH
- require 'vips'
- img = ::Vips::Image.new_from_file(content.path, input_options)
+ 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 format.to_s =~ /jpg|jpeg/i
+ output_options['format'] ||= format.to_s if format.to_s =~ /gif|bmp/i
+ img = ::Vips::Image.new_from_file(content.path, input_options)
img = img.rot("d#{rotate}")
content.update(
img.write_to_buffer(".#{format}", output_options),
'name' => "temp.#{format}",