lib/paperclip/thumbnail.rb in paperclip-2.3.16 vs lib/paperclip/thumbnail.rb in paperclip-2.4.0
- old
+ new
@@ -12,17 +12,28 @@
# will attempt to transform the image into one defined by +target_geometry+
# which is a "WxH"-style string. +format+ will be inferred from the +file+
# unless specified. Thumbnail creation will raise no errors unless
# +whiny+ is true (which it is, by default. If +convert_options+ is
# set, the options will be appended to the convert command upon image conversion
- def initialize file, options = {}, attachment = nil
+ #
+ # Options include:
+ #
+ # +geometry+ - the desired width and height of the thumbnail (required)
+ # +file_geometry_parser+ - an object with a method named +from_file+ that takes an image file and produces its geometry and a +transformation_to+. Defaults to Paperclip::Geometry
+ # +string_geometry_parser+ - an object with a method named +parse+ that takes a string and produces an object with +width+, +height+, and +to_s+ accessors. Defaults to Paperclip::Geometry
+ # +source_file_options+ - flags passed to the +convert+ command that influence how the source file is read
+ # +convert_options+ - flags passed to the +convert+ command that influence how the image is processed
+ # +whiny+ - whether to raise an error when processing fails. Defaults to true
+ # +format+ - the desired filename extension
+ # +animated+ - whether to merge all the layers in the image. Defaults to true
+ def initialize(file, options = {}, attachment = nil)
super
- geometry = options[:geometry]
+ geometry = options[:geometry] # this is not an option
@file = file
@crop = geometry[-1,1] == '#'
- @target_geometry = Geometry.parse geometry
- @current_geometry = Geometry.from_file @file
+ @target_geometry = (options[:string_geometry_parser] || Geometry).parse(geometry)
+ @current_geometry = (options[:file_geometry_parser] || Geometry).from_file(@file)
@source_file_options = options[:source_file_options]
@convert_options = options[:convert_options]
@whiny = options[:whiny].nil? ? true : options[:whiny]
@format = options[:format]
@animated = options[:animated].nil? ? true : options[:animated]