jpegtran-ruby 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/CHANGES.md +27 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +20 -0
- data/README.md +49 -0
- data/Rakefile +5 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/jpegtran-ruby.gemspec +26 -0
- data/lib/jpegtran/configuration.rb +19 -0
- data/lib/jpegtran/version.rb +3 -0
- data/lib/jpegtran.rb +107 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 41fbf992ca7c53ea7fcad679881ca7ed27448d2c
|
4
|
+
data.tar.gz: ff1c1f6b3be42ca8379abf2c1abf9d9225c27538
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d79a3eed9d345a26c6435ce709e26194600386c1e6465db6d66f2c3b4c0ce521ca01bdc04fb593471b6d0f23c3a31751366405dc5dc55a91933e8ed76b30670
|
7
|
+
data.tar.gz: 65958bb41961505a6f1d400f78f56ffdc8363ce2ab8f9f75c32cf7f4a43a30b161aa32caf6aee45b4ddb2bce901e5b076751c011bca4473e22f6b508993e47b3
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format doc --color --backtrace
|
data/.travis.yml
ADDED
data/CHANGES.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
### 0.3.0 (2016-02-20)
|
2
|
+
|
3
|
+
* simplified the code and got rid of runtime dependencies
|
4
|
+
* new gem name
|
5
|
+
* specs
|
6
|
+
|
7
|
+
### 0.1.4 (2015-08-15)
|
8
|
+
|
9
|
+
* minor bugfixes
|
10
|
+
* the `hash-utils` dependency removed
|
11
|
+
|
12
|
+
### 0.1.3 (2011-09-08)
|
13
|
+
|
14
|
+
* the `lookup-hash` dependency removed
|
15
|
+
|
16
|
+
### 0.1.2 (2011-07-30)
|
17
|
+
|
18
|
+
* executing directly by `command-builder`
|
19
|
+
* switch to more modern `hash-utils`
|
20
|
+
|
21
|
+
### 0.1.1 (2011-02-30)
|
22
|
+
|
23
|
+
* some subminor issues
|
24
|
+
|
25
|
+
### 0.1.0 (2011-05-28)
|
26
|
+
|
27
|
+
* initial version
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jpegtran-ruby (0.3.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.0)
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
method_source (0.8.2)
|
12
|
+
pry (0.10.3)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.8.1)
|
15
|
+
slop (~> 3.4)
|
16
|
+
rake (10.4.2)
|
17
|
+
rspec (3.4.0)
|
18
|
+
rspec-core (~> 3.4.0)
|
19
|
+
rspec-expectations (~> 3.4.0)
|
20
|
+
rspec-mocks (~> 3.4.0)
|
21
|
+
rspec-core (3.4.3)
|
22
|
+
rspec-support (~> 3.4.0)
|
23
|
+
rspec-expectations (3.4.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.4.0)
|
26
|
+
rspec-mocks (3.4.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.4.0)
|
29
|
+
rspec-support (3.4.1)
|
30
|
+
slop (3.6.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.11)
|
37
|
+
jpegtran-ruby!
|
38
|
+
pry
|
39
|
+
rake (~> 10.0)
|
40
|
+
rspec (~> 3.0)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.11.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011-2016 Martin Poljak (martin@poljak.cz)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
## Jpegtran
|
2
|
+
|
3
|
+
Provides Ruby interface to the [jpegtran](http://linux.die.net/man/1/jpegtran) tool.
|
4
|
+
|
5
|
+
![Travis CI](https://travis-ci.org/dimko/jpegtran-ruby.svg)
|
6
|
+
|
7
|
+
### Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'jpegtran-ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install jpegtran-ruby
|
22
|
+
|
23
|
+
This gem uses `jpegtran` executable. So it needs to be installed on the machine.
|
24
|
+
Usually it comes with the [libjpeg](http://libjpeg.sourceforge.net) or you can use [MozJPEG](https://github.com/mozilla/mozjpeg).
|
25
|
+
|
26
|
+
### Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require "jpegtran"
|
30
|
+
|
31
|
+
Jpegtran.configured? # will return true (or false)
|
32
|
+
|
33
|
+
options = { progressive: true, optimize: true }
|
34
|
+
Jpegtran.optimize("foo.jpg", options) # will run `jpegtran -progressive -optimize -outfile foo.jpg foo.jpg`
|
35
|
+
```
|
36
|
+
|
37
|
+
Note that `-maxmemory N` option isn't supported.
|
38
|
+
|
39
|
+
### Configuring
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Jpegtran.configure do |config|
|
43
|
+
config.executable = "/usr/local/bin/jpegtran"
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
### Copyright
|
48
|
+
|
49
|
+
Copyright © 2011 – 2016 [Martin Poljak](http://www.martinpoljak.net)
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "jpegtran/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jpegtran-ruby"
|
8
|
+
spec.version = Jpegtran::VERSION
|
9
|
+
spec.authors = ["Martin Poljak", "DM"]
|
10
|
+
spec.email = ["deemox@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby interface to jpegtran tool"
|
13
|
+
spec.description = "Jpegtran provides Ruby interface to the jpegtran tool"
|
14
|
+
spec.homepage = "https://github.com/dimko/jpegtran-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Jpegtran
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
COMMAND = :jpegtran
|
5
|
+
|
6
|
+
def executable=(path)
|
7
|
+
@executable = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def executable
|
11
|
+
@executable ||= default_executable
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_executable
|
15
|
+
path = `which #{COMMAND}`
|
16
|
+
$? == 0 ? path.chomp! : nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/jpegtran.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require_relative "jpegtran/configuration"
|
2
|
+
|
3
|
+
module Jpegtran
|
4
|
+
extend self
|
5
|
+
|
6
|
+
class Error < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
BOOLEAN_ARGS = [
|
10
|
+
:arithmetic, :grayscale, :optimize, :perfect, :progressive,
|
11
|
+
:transpose, :transverse, :trim, :verbose
|
12
|
+
]
|
13
|
+
|
14
|
+
COPY_OPTIONS = [
|
15
|
+
:none, :comments, :all
|
16
|
+
]
|
17
|
+
|
18
|
+
FLIP_OPTIONS = [
|
19
|
+
:horizontal, :vertical
|
20
|
+
]
|
21
|
+
|
22
|
+
def configured?
|
23
|
+
!executable.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def executable
|
27
|
+
configuration.executable
|
28
|
+
end
|
29
|
+
|
30
|
+
def configuration
|
31
|
+
@configuration ||= Configuration.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def configure
|
35
|
+
yield configuration
|
36
|
+
end
|
37
|
+
|
38
|
+
def optimize(path, options = {})
|
39
|
+
cmd = [executable]
|
40
|
+
|
41
|
+
# Boolean arguments
|
42
|
+
options.each_pair do |k, v|
|
43
|
+
if BOOLEAN_ARGS.include?(k) && v
|
44
|
+
cmd << "-#{k}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Fixnum arguments
|
49
|
+
[ :rotate, :restart ].each do |arg|
|
50
|
+
if Fixnum === options[arg]
|
51
|
+
cmd << "-#{arg} #{options[arg]}"
|
52
|
+
elsif options.include?(arg)
|
53
|
+
raise Error.new("Invalid value for :#{arg} option. Fixnum expected.")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# String arguments
|
58
|
+
[ :crop, :scans ].each do |arg|
|
59
|
+
if String === options[arg]
|
60
|
+
cmd << "-#{arg} #{options[arg]}"
|
61
|
+
elsif options.include?(arg)
|
62
|
+
raise Error.new("Invalid value for :#{arg} option. Structured string expected. See 'jpegtran' reference.")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Copy
|
67
|
+
if options.include?(:copy)
|
68
|
+
value = options[:copy].to_sym
|
69
|
+
|
70
|
+
if COPY_OPTIONS.include?(value)
|
71
|
+
cmd << "-copy #{value}"
|
72
|
+
else
|
73
|
+
raise Error.new("Invalid value for :copy. Expected #{COPY_OPTIONS}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Flip
|
78
|
+
if options.include?(:flip)
|
79
|
+
value = options[:flip].to_sym
|
80
|
+
|
81
|
+
if FLIP_OPTIONS.include?(value)
|
82
|
+
cmd << "-flip #{value}"
|
83
|
+
else
|
84
|
+
raise Error.new("Invalid value for :flip. Expected #{FLIP_OPTIONS}")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Outfile
|
89
|
+
if options.include?(:outfile)
|
90
|
+
if String === options[:outfile]
|
91
|
+
out = options[:outfile]
|
92
|
+
else
|
93
|
+
raise Error.new("Invalid value for :outfile option. String expected.")
|
94
|
+
end
|
95
|
+
else
|
96
|
+
out = path.to_s
|
97
|
+
end
|
98
|
+
|
99
|
+
cmd << "-outfile #{out}"
|
100
|
+
cmd << path.to_s
|
101
|
+
cmd = cmd.join(" ")
|
102
|
+
|
103
|
+
IO.popen(cmd) do |f|
|
104
|
+
f.read.chomp
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jpegtran-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Poljak
|
8
|
+
- DM
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.11'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.11'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: pry
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Jpegtran provides Ruby interface to the jpegtran tool
|
71
|
+
email:
|
72
|
+
- deemox@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CHANGES.md
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- jpegtran-ruby.gemspec
|
89
|
+
- lib/jpegtran.rb
|
90
|
+
- lib/jpegtran/configuration.rb
|
91
|
+
- lib/jpegtran/version.rb
|
92
|
+
homepage: https://github.com/dimko/jpegtran-ruby
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.8
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Ruby interface to jpegtran tool
|
116
|
+
test_files: []
|