-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for jpeg-recompress from danielgtaylor/jpeg-archive
- Loading branch information
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'image_optim/worker' | ||
require 'image_optim/option_helpers' | ||
|
||
class ImageOptim | ||
class Worker | ||
# http://www.kokkonen.net/tjko/projects.html | ||
class Jpegrecompress < Worker | ||
QUALITY_OPTION = | ||
option(:quality, 4, 'JPEG quality preset: '\ | ||
'`0` - low, '\ | ||
'`1` - medium, '\ | ||
'`2` - high, '\ | ||
'`3` - veryhigh, '\ | ||
'`4` - lossless') do |v| | ||
OptionHelpers.limit_with_range(v.to_i, 0..4) | ||
end | ||
|
||
QUALITY_OPTIONS = %i(low medium high veryhigh lossless) | ||
|
||
def used_bins | ||
QUALITY_OPTIONS[quality] == :lossless ? [] : [:'jpeg-recompress'] | ||
end | ||
|
||
# Run first [-1] if max_quality < 100 otherwise with normal priority | ||
def run_order | ||
-1 | ||
end | ||
|
||
def optimize(src, dst) | ||
quality_str = QUALITY_OPTIONS[quality] | ||
return false if quality_str == :lossless | ||
src.copy(dst) | ||
args = ['-q', quality_str, dst, dst] | ||
execute(:'jpeg-recompress', *args) && optimized?(src, dst) | ||
end | ||
end | ||
end | ||
end |