Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a level option to gifsicle #51

Merged
merged 16 commits into from
Oct 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## unreleased

* Added options to Gifsicle, specifically --careful (for compatibility) and --optimize for granularity [#51](https://github.com/toy/image_optim/issues/51) [@kaspergrubbe](https://github.com/kaspergrubbe)
* Speedup specs (~8x) [#60](https://github.com/toy/image_optim/issues/60) [@toy](https://github.com/toy)
* `script/worker_analysis` to compare worker chains by optimization, time and losslessness [@toy](https://github.com/toy)
* `Cmd` module to ensure interrupted commands can't go unnoticed [@toy](https://github.com/toy)
Expand Down
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ Worker can be disabled by passing `false` instead of options hash.

### :gifsicle =>
* `:interlace` — Turn interlacing 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`)*

### :jhead =>
Worker has no options
Expand Down
15 changes: 14 additions & 1 deletion lib/image_optim/worker/gifsicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ class Gifsicle < Worker
INTERLACE_OPTION =
option(:interlace, false, 'Turn interlacing on'){ |v| !!v }

LEVEL_OPTION =
option(:level, 3, 'Compression level: '\
'`1` - light and fast, '\
'`2` - normal, '\
'`3` - heavy (slower)') do |v|
OptionHelpers.limit_with_range(v.to_i, 1..3)
end

CAREFUL_OPTION =
option(:careful, false, 'Avoid bugs with some software'){ |v| !!v }

def optimize(src, dst)
args = %W[
--output=#{dst}
--optimize=3
--no-comments
--no-names
--same-delay
Expand All @@ -19,7 +29,10 @@ def optimize(src, dst)
--
#{src}
]

args.unshift('--interlace') if interlace
args.unshift('--careful') if careful
args.unshift("--optimize=#{level}") if level
execute(:gifsicle, *args) && optimized?(src, dst)
end
end
Expand Down