jpegtran 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "hash-utils", ">= 0.15.0"
5
+ gem "pipe-run", ">= 0.2.1"
6
+ gem "command-builder", ">= 0.1.0"
7
+ gem "unix-whereis", ">= 0.1.0"
8
+ gem "lookup-hash", ">= 0.2.0"
9
+
10
+ # Add dependencies to develop your gem here.
11
+ # Include everything needed to run rake, tests, features, etc.
12
+ group :development do
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.5.2"
15
+ end
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ command-builder (0.1.0)
5
+ hash-utils (>= 0.7.0)
6
+ git (1.2.5)
7
+ hash-utils (0.15.0)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ lookup-hash (0.2.0)
13
+ hash-utils (>= 0.11.0)
14
+ pipe-run (0.2.1)
15
+ rake (0.9.0)
16
+ unix-whereis (0.1.0)
17
+ command-builder (>= 0.1.0)
18
+ hash-utils (>= 0.9.0)
19
+ pipe-run (>= 0.1.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ command-builder (>= 0.1.0)
27
+ hash-utils (>= 0.15.0)
28
+ jeweler (~> 1.5.2)
29
+ lookup-hash (>= 0.2.0)
30
+ pipe-run (>= 0.2.1)
31
+ unix-whereis (>= 0.1.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
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.
@@ -0,0 +1,43 @@
1
+ Jpegtran
2
+ ========
3
+
4
+ **Jpegtran** provides Ruby interface to the [`jpegtran`][1] tool.
5
+ Some examples follow: (for details, see module documentation)
6
+
7
+ require "jpegtran"
8
+
9
+ Jpegtran.available? # will return true (or false)
10
+
11
+ Jpegtran.optimize("foo.jpg", { :progressive => true, :optimize => true })
12
+ # will run 'jpegtran -progressive -optimize -outfile foo.jpg foo.jpg'
13
+
14
+ It can be also run asynchronously by non-blocking way (with [`eventmachine`][4])
15
+ simply by giving block to `#optimize`. See documentation.
16
+
17
+ ### Unsupported Options
18
+
19
+ The `-maxmemory N` option isn't supported.
20
+
21
+
22
+
23
+
24
+ Contributing
25
+ ------------
26
+
27
+ 1. Fork it.
28
+ 2. Create a branch (`git checkout -b 20101220-my-change`).
29
+ 3. Commit your changes (`git commit -am "Added something"`).
30
+ 4. Push to the branch (`git push origin 20101220-my-change`).
31
+ 5. Create an [Issue][2] with a link to your branch.
32
+ 6. Enjoy a refreshing Diet Coke and wait.
33
+
34
+ Copyright
35
+ ---------
36
+
37
+ Copyright © 2011 [Martin Kozák][3]. See `LICENSE.txt` for
38
+ further details.
39
+
40
+ [1]: http://linux.die.net/man/1/jpegtran
41
+ [2]: http://github.com/martinkozak/jpegtran/issues
42
+ [3]: http://www.martinkozak.net/
43
+ [4]: http://rubyeventmachine.com/
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "jpegtran"
17
+ gem.homepage = "https://github.com/martinkozak/jpegtran"
18
+ gem.license = "MIT"
19
+ gem.summary = "Ruby interface to 'jpegtran' tool."
20
+ gem.email = "martinkozak@martinkozak.net"
21
+ gem.authors = ["Martin Kozák"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/rdoctask'
30
+ Rake::RDocTask.new do |rdoc|
31
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
32
+
33
+ rdoc.rdoc_dir = 'rdoc'
34
+ rdoc.title = "qrpc #{version}"
35
+ rdoc.rdoc_files.include('README*')
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{jpegtran}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Martin Kozák}]
12
+ s.date = %q{2011-05-27}
13
+ s.email = %q{martinkozak@martinkozak.net}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "jpegtran.gemspec",
27
+ "lib/jpegtran.rb",
28
+ "test",
29
+ "test.jpg"
30
+ ]
31
+ s.homepage = %q{https://github.com/martinkozak/jpegtran}
32
+ s.licenses = [%q{MIT}]
33
+ s.require_paths = [%q{lib}]
34
+ s.rubygems_version = %q{1.8.3}
35
+ s.summary = %q{Ruby interface to 'jpegtran' tool.}
36
+
37
+ if s.respond_to? :specification_version then
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<hash-utils>, [">= 0.15.0"])
42
+ s.add_runtime_dependency(%q<pipe-run>, [">= 0.2.1"])
43
+ s.add_runtime_dependency(%q<command-builder>, [">= 0.1.0"])
44
+ s.add_runtime_dependency(%q<unix-whereis>, [">= 0.1.0"])
45
+ s.add_runtime_dependency(%q<lookup-hash>, [">= 0.2.0"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
48
+ else
49
+ s.add_dependency(%q<hash-utils>, [">= 0.15.0"])
50
+ s.add_dependency(%q<pipe-run>, [">= 0.2.1"])
51
+ s.add_dependency(%q<command-builder>, [">= 0.1.0"])
52
+ s.add_dependency(%q<unix-whereis>, [">= 0.1.0"])
53
+ s.add_dependency(%q<lookup-hash>, [">= 0.2.0"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<hash-utils>, [">= 0.15.0"])
59
+ s.add_dependency(%q<pipe-run>, [">= 0.2.1"])
60
+ s.add_dependency(%q<command-builder>, [">= 0.1.0"])
61
+ s.add_dependency(%q<unix-whereis>, [">= 0.1.0"])
62
+ s.add_dependency(%q<lookup-hash>, [">= 0.2.0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,205 @@
1
+ # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
4
+ require "command-builder"
5
+ require "pipe-run"
6
+ require "unix/whereis"
7
+ require "lookup-hash"
8
+ require "hash-utils/object" # >= 0.15.0
9
+
10
+ ##
11
+ # The +jpegtran+ tool command frontend.
12
+ # @see http://linux.die.net/man/1/jpegtran
13
+ #
14
+
15
+ module Jpegtran
16
+
17
+ ##
18
+ # Holds +jpegoptim+ command.
19
+ #
20
+
21
+ COMMAND = :jpegtran
22
+
23
+ ##
24
+ # Indicates turn on/off style arguments.
25
+ #
26
+
27
+ BOOLEAN_ARGS = LookupHash[
28
+ :optimize, :progressive, :grayscale, :perfect, :transpose,
29
+ :transverse, :trim, :arithmetic
30
+ ]
31
+
32
+ ##
33
+ # Holds copy values.
34
+ #
35
+
36
+ COPY_OPTIONS = LookupHash[
37
+ :none, :comments, :all
38
+ ]
39
+
40
+ ##
41
+ # Holds flip values.
42
+ #
43
+
44
+ FLIP_OPTIONS = LookupHash[
45
+ :horizontal, :vertical
46
+ ]
47
+
48
+ ##
49
+ # Result structure.
50
+ #
51
+ # Return value contains only +:errors+ member. +:errors+ contains
52
+ # simply array of error messages.
53
+ #
54
+
55
+ Result = Struct::new(:errors)
56
+
57
+ ##
58
+ # Holds output matchers.
59
+ #
60
+
61
+ ERROR = /jpegtran:\s*(.*)\s*/
62
+
63
+ ##
64
+ # Checks if +jpegtran+ is available.
65
+ # @return [Boolean] +true+ if it is, +false+ in otherwise
66
+ #
67
+
68
+ def self.available?
69
+ return Whereis.available? self::COMMAND
70
+ end
71
+
72
+ ##
73
+ # Performs optimizations above file. For list of arguments, see
74
+ # reference of +jpegtran+.
75
+ #
76
+ # If block is given, runs +jpegoptim+ asynchronously. In that case,
77
+ # +em-pipe-run+ file must be already required.
78
+ #
79
+ # @param [String, Array] paths file path or array of paths for optimizing
80
+ # @param [Hash] options options
81
+ # @param [Proc] block block for giving back the results
82
+ # @return [Struct] see {Result}
83
+ #
84
+
85
+ def self.optimize(path, options = { }, &block)
86
+
87
+ # Command
88
+ cmd = CommandBuilder::new(self::COMMAND)
89
+ cmd.separators = ["-", " ", "-", " "]
90
+
91
+ # Turn on/off arguments
92
+ options.each_pair do |k, v|
93
+ if v.true? and self::BOOLEAN_ARGS.has_key? k
94
+ cmd << k
95
+ end
96
+ end
97
+
98
+ # Rotate
99
+ if options[:rotate].kind_of? Integer
100
+ cmd.arg(:rotate, options[:rotate].to_i)
101
+ elsif options.has_key? :rotate
102
+ raise Exception::new("Invalid value for :rotate option. Integer expected.")
103
+ end
104
+
105
+ # Rotate
106
+ if options[:restart].kind_of? Integer
107
+ cmd.arg(:restart, options[:restart].to_i)
108
+ elsif options.has_key? :restart
109
+ raise Exception::new("Invalid value for :restart option. Integer expected.")
110
+ end
111
+
112
+ # Crop
113
+ if options[:crop].kind_of? String
114
+ cmd.arg(:crop, options[:crop].to_s)
115
+ elsif options.has_key? :crop
116
+ raise Exception::new("Invalid value for :crop option. Structured string expected. See 'jpegtran' reference.")
117
+ end
118
+
119
+ # Scans
120
+ if options[:scans].kind_of? String
121
+ cmd.arg(:scans, options[:scans].to_s)
122
+ elsif options.has_key? :scans
123
+ raise Exception::new("Invalid value for :scans option. String expected.")
124
+ end
125
+
126
+ # Copy
127
+ if options.has_key? :copy
128
+ value = options[:copy].to_sym
129
+ if self::COPY_OPTIONS.has_key? value
130
+ cmd.arg(:copy, value)
131
+ else
132
+ raise Exception::new("Invalid value for :copy. Expected " << self::COPY_OPTIONS.to_s)
133
+ end
134
+ end
135
+
136
+ # Flip
137
+ if options.has_key? :flip
138
+ value = options[:flip].to_sym
139
+ if self::FLIP_OPTIONS.has_key? value
140
+ cmd.arg(:flip, value)
141
+ else
142
+ raise Exception::new("Invalid value for :flip. Expected " << self::FLIP_OPTIONS.to_s)
143
+ end
144
+ end
145
+
146
+ # Outfile
147
+ if options.has_key? :outfile
148
+ if options[:outfile].kind_of? String
149
+ value = options[:outfile].to_s
150
+ else
151
+ raise Exception::new("Invalid value for :outfile option. String expected.")
152
+ end
153
+ else
154
+ value = path.to_s
155
+ end
156
+
157
+ cmd.arg(:outfile, value)
158
+
159
+ # Runs the command
160
+ cmd << path.to_s
161
+
162
+ if options[:debug] == true
163
+ STDERR.write cmd.to_s + "\n"
164
+ end
165
+
166
+ cmd = cmd.to_s
167
+
168
+ # Blocking
169
+ if block.nil?
170
+ #output = Pipe.run(cmd)
171
+ Pipe.run(cmd)
172
+
173
+ # Parses output
174
+ #errors = __parse_output(output)
175
+ #return self::Result::new(errors)
176
+
177
+ # Non-blocking
178
+ else
179
+ Pipe.run(cmd) do #|output|
180
+ # errors = __parse_output(output)
181
+ # block.call(self::Result::new(errors))
182
+ block.call()
183
+ end
184
+ end
185
+
186
+ end
187
+
188
+
189
+ # private
190
+ #
191
+ ##
192
+ # Parses output.
193
+ #
194
+ #
195
+ # def self.__parse_output(output)
196
+ # errors = [ ]
197
+ # output.each_line do |line|
198
+ # if m = line.match(self::ERROR)
199
+ # errors << m[1]
200
+ # end
201
+ # end
202
+ #
203
+ # return errors
204
+ # end
205
+ end
data/test ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+
4
+ $:.push("./lib")
5
+ require "jpegtran"
6
+ require "em-pipe-run"
7
+
8
+ EM::run do
9
+ puts Jpegtran.available?.inspect
10
+ Jpegtran.optimize("./test.jpg", { :optimize => true, :progressive => true, :debug => true }) do |results|
11
+ puts results.inspect
12
+ end
13
+
14
+ puts "after"
15
+ end
Binary file
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jpegtran
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - "Martin Koz\xC3\xA1k"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-27 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hash-utils
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.15.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: pipe-run
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: command-builder
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.1.0
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: unix-whereis
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.1.0
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: lookup-hash
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.2.0
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ requirement: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: jeweler
83
+ requirement: &id007 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: 1.5.2
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *id007
92
+ description:
93
+ email: martinkozak@martinkozak.net
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.md
101
+ files:
102
+ - .document
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - VERSION
109
+ - jpegtran.gemspec
110
+ - lib/jpegtran.rb
111
+ - test
112
+ - test.jpg
113
+ homepage: https://github.com/martinkozak/jpegtran
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 4296075217821261876
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.3
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Ruby interface to 'jpegtran' tool.
143
+ test_files: []
144
+