Skip to content

Commit

Permalink
run gifsicle two times: one with interlace off and one with on for be…
Browse files Browse the repository at this point in the history
…st result, resolves #70
  • Loading branch information
toy committed Nov 6, 2014
1 parent 9ff70bc commit a14ebb1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Worker can be disabled by passing `false` instead of options hash.
* `:level` — Compression level: `0` - don't compress, `1` - fast, `2` - normal, `3` - extra, `4` - extreme *(defaults to `4`)*

### :gifsicle =>
* `:interlace` — Interlace: `true` - interlace on, `false` - interlace off, `nil` - as is in original image *(defaults to `false`)*
* `:interlace` — Interlace: `true` - interlace on, `false` - interlace off, `nil` - as is in original image (defaults to running two instances, one with interlace off and one with on) *(defaults to `false`)*
* `:level` — Compression level: `1` - light and fast, `2` - normal, `3` - heavy (slower) *(defaults to `3`)*
* `:careful` — Avoid bugs with some software *(defaults to `false`)*

Expand Down
10 changes: 5 additions & 5 deletions lib/image_optim/runner/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ def wrap_regex(width)
fail "Unknown type #{type}"
end

description_lines = %W[
#{option_definition.description.gsub(' - ', ' - ')}
(defaults to #{default})
].join(' ')
description = option_definition.description.gsub(' - ', ' - ')
unless description['(defaults']
description << " (defaults to #{default})"
end

op.on("--#{bin}-#{name} #{marking}", type, *description_lines) do |value|
op.on("--#{bin}-#{name} #{marking}", type, description) do |value|
options[bin] = {} unless options[bin].is_a?(Hash)
options[bin][option_definition.name.to_sym] = value
end
Expand Down
1 change: 1 addition & 0 deletions lib/image_optim/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Worker

class << self
# Default init for worker is new
# Check example of override in gifsicle worker
alias_method :init, :new

# List of available workers
Expand Down
14 changes: 13 additions & 1 deletion lib/image_optim/worker/gifsicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ class ImageOptim
class Worker
# http://www.lcdf.org/gifsicle/
class Gifsicle < Worker
# If interlace specified initialize one instance
# Otherwise initialize two, one with interlace off and one with on
def self.init(image_optim, options)
return super if options.key?(:interlace)

[false, true].map do |interlace|
new(image_optim, options.merge(:interlace => interlace))
end
end

INTERLACE_OPTION =
option(:interlace, false, TrueFalseNil, 'Interlace: '\
'`true` - interlace on, '\
'`false` - interlace off, '\
'`nil` - as is in original image') do |v|
'`nil` - as is in original image '\
'(defaults to running two instances, one with interlace off and '\
'one with on)') do |v|
TrueFalseNil.convert(v)
end

Expand Down
11 changes: 5 additions & 6 deletions script/update_worker_options_in_readme
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ def write_worker_options(io, klass)
io.puts 'Worker has no options'
else
klass.option_definitions.each do |option_definition|
io.puts %W[
*
`:#{option_definition.name}`
#{option_definition.description}
*(defaults to `#{option_definition.default.inspect}`)*
].join(' ')
line = "* `:#{option_definition.name}` — #{option_definition.description}"
unless line['(defaults']
line << " *(defaults to `#{option_definition.default.inspect}`)*"
end
io.puts line
end
end
io.puts
Expand Down

0 comments on commit a14ebb1

Please sign in to comment.