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
- PLUGIN_NAME_R =
/\A[a-zA-Z]+\z/.freeze
- DISABLE_PLUGINS_OPTION =
option(:disable_plugins, [], 'List of plugins to disable') do |v| parse_plugin_names(v) end
- ENABLE_PLUGINS_OPTION =
option(:enable_plugins, [], 'List of plugins to enable') do |v| parse_plugin_names(v) 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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/image_optim/worker/svgo.rb', line 41 def optimize(src, dst, = {}) args = %W[ --input #{src} --output #{dst} ] if resolve_bin!(:svgo).version >= '2.0.0' unless disable_plugins.empty? && enable_plugins.empty? config_file = plugins_config_file args.unshift "--config=#{config_file.path}" end else disable_plugins.each do |plugin_name| args.unshift "--disable=#{plugin_name}" end enable_plugins.each do |plugin_name| args.unshift "--enable=#{plugin_name}" end end args.unshift "--precision=#{precision}" if allow_lossy execute(:svgo, args, ) && optimized?(src, dst) end |