Class: Pageflow::PaperclipProcessors::Webp Private
- Inherits:
-
Paperclip::Processor
- Object
- Paperclip::Processor
- Pageflow::PaperclipProcessors::Webp
- Defined in:
- lib/pageflow/paperclip_processors/webp.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- ANIMATED_FORMATS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[.gif].freeze
Instance Method Summary collapse
-
#initialize(file, options = {}, attachment = nil) ⇒ Webp
constructor
private
A new instance of Webp.
- #make ⇒ Object private
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ Webp
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Webp.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pageflow/paperclip_processors/webp.rb', line 9 def initialize(file, = {}, = nil) super geometry = [:geometry].to_s @should_crop = geometry[-1, 1] == '#' @target_geometry = Paperclip::Geometry.parse(geometry) @whiny = .fetch(:whiny, true) @current_format = File.extname(file.path) @basename = File.basename(@file.path, @current_format) end |
Instance Method Details
#make ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pageflow/paperclip_processors/webp.rb', line 22 def make source = @file filename = [@basename, '.webp'].join destination = Paperclip::TempfileFactory.new.generate(filename) begin thumbnail = Vips::Image.thumbnail( ANIMATED_FORMATS.include?(@current_format) ? "#{source.path}[n=-1]" : source.path, width, size: @should_crop ? :both : :down, height: height, crop: crop ) thumbnail.webpsave(destination.path) rescue Vips::Error => e if @whiny = "There was an error processing the thumbnail for #{@basename}:\n" + e. raise Paperclip::Error, end end destination end |