Class: ImageOptim::Worker::Svgo
- Inherits:
-
ImageOptim::Worker
- Object
- ImageOptim::Worker
- ImageOptim::Worker::Svgo
- Defined in:
- lib/image_optim/worker/svgo.rb
Overview
Constant Summary collapse
- DISABLE_PLUGINS_OPTION =
option(:disable_plugins, [], 'List of plugins to disable') do |v| Array(v).map(&:to_s) end
- ENABLE_PLUGINS_OPTION =
option(:enable_plugins, [], 'List of plugins to enable') do |v| Array(v).map(&:to_s) end
- ALLOW_LOSSY_OPTION =
option(:allow_lossy, false, 'Allow precision option'){ |v| !!v }
- PRECISION_OPTION =
option(:precision, 3, 'Number of digits in the fractional part ' \ '`0`..`20`, ignored in default/lossless mode') \ do |v, opt_def| if allow_lossy OptionHelpers.limit_with_range(v.to_i, 0..20) else if v != opt_def.default warn "#{self.class.bin_sym} #{opt_def.name} #{v} ignored " \ 'in default/lossless mode' end opt_def.default end end
Instance Method Summary collapse
Methods inherited from ImageOptim::Worker
#image_formats, #initialize, #inspect, #optimized?, #options, #resolve_used_bins!, #run_order, #used_bins
Methods included from ClassMethods
#bin_sym, #create_all, #create_all_by_format, extended, #inherited, #klasses, #option, #option_definitions
Constructor Details
This class inherits a constructor from ImageOptim::Worker
Instance Method Details
#optimize(src, dst, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/image_optim/worker/svgo.rb', line 38 def optimize(src, dst, = {}) args = %W[ --input #{src} --output #{dst} ] disable_plugins.each do |plugin_name| args.unshift "--disable=#{plugin_name}" end enable_plugins.each do |plugin_name| args.unshift "--enable=#{plugin_name}" end args.unshift "--precision=#{precision}" if allow_lossy execute(:svgo, args, ) && optimized?(src, dst) end |