dragonfly_mozjpeg 0.0.2
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/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dragonfly_mozjpeg.gemspec +25 -0
- data/lib/dragonfly_mozjpeg/plugin.rb +20 -0
- data/lib/dragonfly_mozjpeg/processors/lossless.rb +17 -0
- data/lib/dragonfly_mozjpeg/processors/lossy.rb +17 -0
- data/lib/dragonfly_mozjpeg/utils.rb +45 -0
- data/lib/dragonfly_mozjpeg/version.rb +3 -0
- data/lib/dragonfly_mozjpeg.rb +7 -0
- data/vendor/mozjpeg/LICENSE.txt +7 -0
- data/vendor/mozjpeg/linux/cjpeg +0 -0
- data/vendor/mozjpeg/linux/jpegtran +0 -0
- data/vendor/mozjpeg/linux/libjpeg.so.62 +0 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c4165de7a1fd87f6c56fdcfd2b107cf1ea87f99
|
4
|
+
data.tar.gz: c00a90eada9a77a871a92949755e4f019d2e45fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7cd39ce4227cf3f883924b2c3b8a88189bad4b2a8001dd33ea8420ffd4bbc5c12d9ca92c2b6edc3f65062911512f6bd041bafff10649f8c415529b0aa8e0d665
|
7
|
+
data.tar.gz: 604118c1f8884c634e9d395be2210b98817ab4d23f75d341da433ef2c90ec620bbe1f615ab6b24e82d0b7e6c767fbcf5eb3132a4ac41013fc15d9be2d48ed5d1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright 2017 Jurema and it's authors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# dragonfly mozjpeg
|
2
|
+
|
3
|
+
Plugin for [mozilla's](https://github.com/mozilla/mozjpeg) cjpeg and jpegtran encoders for [dragonfly](https://github.com/markevans/dragonfly).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dragonfly_mozjpeg'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or
|
20
|
+
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
$ gem install dragonfly_mozjpeg
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Dragonfly.app.configure do
|
30
|
+
plugin :mozjpeg
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
Overwrite default binaries, For example:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Dragonfly.app.configure do
|
38
|
+
plugin :mozjpeg,
|
39
|
+
cjpeg: '/opt/mozjpeg/bin/cjpeg',
|
40
|
+
jpegtran: '/opt/mozjpeg/bin/jpegtran'
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
### Processors
|
45
|
+
|
46
|
+
#### Lossy
|
47
|
+
|
48
|
+
Lossy compression with cjpeg, and you can pass cjpeg options. For example:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
image.lossy([:noovershoot, quality: "70,60", sample: "2x2", smooth: 10])
|
52
|
+
```
|
53
|
+
#### Lossless
|
54
|
+
|
55
|
+
Lossless compression with jpegtran, jpegtran and you can pass options, For example:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
image.lossless([:grayscale, :trim, copy: :none, flip: :horizontal])
|
59
|
+
```
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome at <https://github.com/jurema/dragonfly_mozjpeg>.
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
This gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT), see LICENSE.txt.
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dragonfly_mozjpeg"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dragonfly_mozjpeg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dragonfly_mozjpeg'
|
8
|
+
spec.version = DragonflyMozjpeg::VERSION
|
9
|
+
spec.authors = ['Jurema']
|
10
|
+
spec.email = ['oops@jurema.la']
|
11
|
+
|
12
|
+
spec.summary = 'Dragonfly analysers and processors for libvips image processing library.'
|
13
|
+
spec.homepage = 'https://github.com/jurema/dragonfly_mozjpeg'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'dragonfly', '~> 1.0'
|
22
|
+
spec.add_dependency 'os', '~> 0.9.6'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'dragonfly_mozjpeg/processors/lossy'
|
2
|
+
require 'dragonfly_mozjpeg/processors/lossless'
|
3
|
+
require 'dragonfly_mozjpeg/utils'
|
4
|
+
|
5
|
+
module DragonflyMozjpeg
|
6
|
+
class Plugin
|
7
|
+
|
8
|
+
BASE_PATH = File.expand_path(File.join(__dir__, '../../vendor/mozjpeg'))
|
9
|
+
|
10
|
+
def call(app, options = {})
|
11
|
+
app.env[:cjpeg] = Utils.check_binary(options[:cjpeg], 'cjpeg')
|
12
|
+
app.env[:jpegtran] = Utils.check_binary(options[:jpegtran], 'jpegtran')
|
13
|
+
|
14
|
+
app.add_processor :lossy, Processors::Lossy.new
|
15
|
+
app.add_processor :lossless, Processors::Lossless.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Dragonfly::App.register_plugin(:mozjpeg) { DragonflyMozjpeg::Plugin.new }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'dragonfly_mozjpeg/utils'
|
2
|
+
|
3
|
+
module DragonflyMozjpeg
|
4
|
+
module Processors
|
5
|
+
class Lossless
|
6
|
+
def call(content, opts = nil)
|
7
|
+
content.shell_update ext: 'jpg' do |input, output|
|
8
|
+
"#{content.env[:jpegtran]} #{Utils.stringify_options(opts)} -outfile #{output} #{input}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_url(url_attributes, format, options = {})
|
13
|
+
url_attributes.ext = format.to_s
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'dragonfly_mozjpeg/utils'
|
2
|
+
|
3
|
+
module DragonflyMozjpeg
|
4
|
+
module Processors
|
5
|
+
class Lossy
|
6
|
+
def call(content, opts = nil)
|
7
|
+
content.shell_update ext: 'jpg' do |input, output|
|
8
|
+
"#{content.env[:cjpeg]} #{Utils.stringify_options(opts)} -outfile #{output} #{input}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_url(url_attributes, format, options = {})
|
13
|
+
url_attributes.ext = format.to_s
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'os'
|
2
|
+
|
3
|
+
module DragonflyMozjpeg
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def logger
|
9
|
+
@logger ||= Logger.new(STDOUT)
|
10
|
+
@logger.level ||= Logger::WARN
|
11
|
+
@logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_binary(current, file)
|
15
|
+
if File.exists?(current)
|
16
|
+
current
|
17
|
+
elsif OS.linux? && OS.bits == 64
|
18
|
+
File.join(BASE_PATH, "linux/#{file}")
|
19
|
+
else
|
20
|
+
logger.warn("dragonfly_mozjpeg: missing #{file} path")
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def stringify_options(opts = nil)
|
26
|
+
return '' if opts.nil?
|
27
|
+
|
28
|
+
if opts.is_a? String
|
29
|
+
opts.gsub('-outfile', '')
|
30
|
+
elsif opts.is_a? Array
|
31
|
+
opts[-1] = opts.last.map do |k,v|
|
32
|
+
" -#{k} #{v}" unless k.to_s == 'outfile'
|
33
|
+
end.join[2..-1] if opts.last.is_a? Hash
|
34
|
+
" -#{(opts - ['outfile']).join(' -')}"
|
35
|
+
elsif opts.is_a? Hash
|
36
|
+
opts.map do |k,v|
|
37
|
+
" -#{k} #{v}" unless k.to_s == 'outfile'
|
38
|
+
end.join
|
39
|
+
else
|
40
|
+
''
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
2
|
+
|
3
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
4
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
5
|
+
* Neither the name of the mozjpeg Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
6
|
+
|
7
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dragonfly_mozjpeg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jurema
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dragonfly
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: os
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- oops@jurema.la
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- bin/console
|
67
|
+
- bin/setup
|
68
|
+
- dragonfly_mozjpeg.gemspec
|
69
|
+
- lib/dragonfly_mozjpeg.rb
|
70
|
+
- lib/dragonfly_mozjpeg/plugin.rb
|
71
|
+
- lib/dragonfly_mozjpeg/processors/lossless.rb
|
72
|
+
- lib/dragonfly_mozjpeg/processors/lossy.rb
|
73
|
+
- lib/dragonfly_mozjpeg/utils.rb
|
74
|
+
- lib/dragonfly_mozjpeg/version.rb
|
75
|
+
- vendor/mozjpeg/LICENSE.txt
|
76
|
+
- vendor/mozjpeg/linux/cjpeg
|
77
|
+
- vendor/mozjpeg/linux/jpegtran
|
78
|
+
- vendor/mozjpeg/linux/libjpeg.so.62
|
79
|
+
homepage: https://github.com/jurema/dragonfly_mozjpeg
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.6.10
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Dragonfly analysers and processors for libvips image processing library.
|
103
|
+
test_files: []
|