lib/morandi.rb in morandi-0.9.0 vs lib/morandi.rb in morandi-0.9.1
- old
+ new
@@ -22,24 +22,31 @@
type.name == 'jpeg'
rescue
false
end
+ def self.default_icc_path(path)
+ "#{path}.icc.jpg"
+ end
- def initialize(file, scale_to, options)
+ def initialize(file, user_options, local_options={})
@file = file
- #@size = size
- @scale_to = scale_to
- @options = options || {}
- @width, @height = options['output.width'], options['output.height']
+ user_options.keys.grep(/^path/).each { |k| user_options.delete(k) }
+ # Give priority to user_options
+ @options = (local_options || {}).merge(user_options || {})
+ @local_options = local_options
+
+ @scale_to = @options['output.max']
+ @width, @height = @options['output.width'], @options['output.height']
+
load_file = @file
type, width, height = Gdk::Pixbuf.get_file_info(load_file)
if type.name.eql?('jpeg')
- icc_file = "#{@file}.icc.jpg"
+ icc_file = local_options['path.icc'] || ImageProcessor.default_icc_path(@file)
if valid_jpeg?(icc_file) || system("jpgicc", "-q97", @file, icc_file)
load_file = icc_file
end
end
@@ -99,11 +106,11 @@
def apply_colour_manipulations!
#STDERR.puts "FILTER: #{options.inspect}"
if options['brighten'].to_i.nonzero?
brighten = [ [ 5 * options['brighten'], -100 ].max, 100 ].min
- STDERR.puts([:brighten, brighten].inspect)
+ #STDERR.puts([:brighten, brighten].inspect)
@pb = PixbufUtils.brightness(@pb, brighten)
end
if options['gamma'] && (options['gamma'] != 1.0)
@pb = PixbufUtils.gamma(@pb, options['gamma'])
end
@@ -169,10 +176,14 @@
if crop.nil? && config_for('image.auto-crop').eql?(false)
return
end
+ if crop.is_a?(String) && crop =~ /^\d+,\d+,\d+,\d+/
+ crop = crop.split(/,/).map(&:to_i)
+ end
+
crop = nil unless crop.is_a?(Array) && crop.size.eql?(4) && crop.all? { |i|
i.kind_of?(Numeric)
}
# can't crop, won't crop
@@ -241,11 +252,11 @@
@pb.save(fn, 'jpeg', :quality => quality)
end
end
module_function
- def process(file_in, settings, out_file)
- pro = ImageProcessor.new(file_in, settings['output.max'], settings)
+ def process(file_in, options, out_file, local_options = {})
+ pro = ImageProcessor.new(file_in, options, local_options)
pro.process!
pro.write_to_jpeg(out_file)
end
end