class Paperclip::PhantomProcessor
Phantom SVG processor for Paperclip
Attributes
dst[RW]
file[RW]
format[RW]
height[RW]
width[RW]
Public Class Methods
new(file, options = {}, attachment = nil)
click to toggle source
Calls superclass method
# File lib/paperclip_processors/phantom_processor.rb, line 8 def initialize(file, options = {}, attachment = nil) super @format = options.fetch(:format, :svg) @height = options.fetch(:height, 64) @width = options.fetch(:width, 64) @base_name = File.basename(@file.path, '.*') @name = options[:output_name] || @base_name @svg = Phantom::SVG::Base.new(@file.path) end
Public Instance Methods
make()
click to toggle source
# File lib/paperclip_processors/phantom_processor.rb, line 19 def make case @format.to_sym when :svg then _create_svg when :png then _create_png else raise 'Format not supported' end end
Private Instance Methods
_create_png()
click to toggle source
# File lib/paperclip_processors/phantom_processor.rb, line 39 def _create_png @dst = Tempfile.new([@name, '.png']).tap do |dst| Paperclip.log "[PhantomSVG] Creating PNG #{@output_name} @ #{@height}x#{@width}" if @whiny @svg.height = height @svg.width = width @svg.save_apng(dst.path) end end
_create_svg()
click to toggle source
# File lib/paperclip_processors/phantom_processor.rb, line 30 def _create_svg @dst = Tempfile.new([@name, '.svg']).tap do |dst| Paperclip.log "[PhantomSVG] Creating SVG #{@output_name}" if @whiny @svg.height = height @svg.width = width @svg.save_svg(dst.path) end end