paperclip-mozjpeg 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/paperclip-mozjpeg.rb +64 -0
- data/lib/paperclip-mozjpeg/version.rb +3 -0
- data/paperclip-mozjpeg.gemspec +30 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3ce4f0104d68fc4f70193335fa25e9f6befdef8b
|
4
|
+
data.tar.gz: 10b353401582c591bb8de5544c18f6736c138d19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38b3f418e9a3f037fdc62d78074dd217a979b36c943c9626c3e1e8c59cced3b571124cf03d1e56676039f1927ff534f750478300c14f767be38baf2bd5823856
|
7
|
+
data.tar.gz: 22631c0733fe9a257cc931c40c661a9fc1b4c242fd38030f85aa16acffa0d9c2de34d9d56cd111932f15611dc3a81fd3a250ed4dbb803064a8e14841adb7e2a6
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# About
|
2
|
+
|
3
|
+
This repository contains the ruby library which adds file processor to compress JPEG images uploaded using the [paperclip](https://github.com/thoughtbot/paperclip) gem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'paperclip-mozjpeg'
|
11
|
+
|
12
|
+
# To use bundled binaries of MozJPEG 3.0 for Mac OS X, Linux and Windows add:
|
13
|
+
gem 'mozjpeg'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install paperclip-mozjpeg
|
23
|
+
|
24
|
+
To install bundled binaries (must `require 'mozjpeg'` if not using bundler):
|
25
|
+
|
26
|
+
$ gem install mozjpeg
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
class User < ActiveRecord::Base
|
32
|
+
has_attached_file :avatar, :styles => {
|
33
|
+
:tiny => {
|
34
|
+
geometry: '190x190>',
|
35
|
+
mozjpeg_options: '-quality 30',
|
36
|
+
},
|
37
|
+
:large => {
|
38
|
+
geometry: '1280x1280>',
|
39
|
+
mozjpeg_options: '-quality 70 -quant-table 2 -notrellis',
|
40
|
+
}
|
41
|
+
},
|
42
|
+
processors: [ :thumbnail, :mozjpeg ]
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
If you don't want to use the `mozjpeg` gem bundled binaries and want to specify the path to mozjpeg (cjpeg) or it is not in the `PATH` use the `mozjpeg_path` option.
|
47
|
+
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
This gem is licensed under the MIT license.
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
1. Fork it ( https://github.com/svoboda-jan/paperclip-mozjpeg/fork )
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "paperclip/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,64 @@
|
|
1
|
+
require "paperclip-mozjpeg/version"
|
2
|
+
require 'paperclip'
|
3
|
+
|
4
|
+
module Paperclip
|
5
|
+
|
6
|
+
# Handles JPEG and PNG compression.
|
7
|
+
class Mozjpeg < Processor
|
8
|
+
|
9
|
+
attr_accessor :whiny, :mozjpeg_options
|
10
|
+
|
11
|
+
# Compresses the +file+ using MozJPEG's cjpeg command.
|
12
|
+
# Compression will raise no errors unless +whiny+ is true
|
13
|
+
# (which it is, by default).
|
14
|
+
#
|
15
|
+
# Options include:
|
16
|
+
#
|
17
|
+
# +geometry+ - the desired width and height of the thumbnail (required)
|
18
|
+
# +whiny+ - whether to raise an error when processing fails. Defaults to true
|
19
|
+
def initialize(file, options = {}, attachment = nil)
|
20
|
+
super
|
21
|
+
@geometry = options[:geometry].to_s
|
22
|
+
@mozjpeg_options = options[:mozjpeg_options]
|
23
|
+
@whiny = options.fetch(:whiny, true)
|
24
|
+
@use_system_binaries = options.fetch(:use_system_binaries, false)
|
25
|
+
@mozjpeg_path = options.fetch(:mozjpeg_path, nil)
|
26
|
+
@current_format = File.extname(@file.path)
|
27
|
+
@basename = File.basename(@file.path, @current_format)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Performs the compression of the +file+. Returns the Tempfile
|
31
|
+
# that contains the new image.
|
32
|
+
def make
|
33
|
+
src = @file
|
34
|
+
filename = [@basename, @format ? ".#{@format}" : ""].join
|
35
|
+
dst = TempfileFactory.new.generate(filename)
|
36
|
+
|
37
|
+
begin
|
38
|
+
parameters = []
|
39
|
+
parameters << mozjpeg_options
|
40
|
+
parameters << "-outfile :dest"
|
41
|
+
parameters << ":source"
|
42
|
+
|
43
|
+
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
44
|
+
|
45
|
+
success = cjpeg(parameters, :source => "#{File.expand_path(src.path)}", :dest => File.expand_path(dst.path))
|
46
|
+
rescue Cocaine::ExitStatusError => e
|
47
|
+
raise Paperclip::Error, "There was an error processing the file for #{@basename}" if @whiny
|
48
|
+
rescue Cocaine::CommandNotFoundError => e
|
49
|
+
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `cjpeg` command. Please install MozJPEG.")
|
50
|
+
end
|
51
|
+
|
52
|
+
dst
|
53
|
+
end
|
54
|
+
|
55
|
+
def cjpeg(arguments = "", local_options = {})
|
56
|
+
if !@use_system_binaries && defined?(::Mozjpeg::VERSION)
|
57
|
+
cmd = ::Mozjpeg.cjpeg_path
|
58
|
+
end
|
59
|
+
cmd ||= ( @mozjpeg_path || 'cjpeg')
|
60
|
+
Paperclip.run(cmd, arguments, local_options)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paperclip-mozjpeg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paperclip-mozjpeg"
|
8
|
+
spec.version = PaperclipMozjpeg::VERSION
|
9
|
+
spec.authors = ["Jan Svoboda"]
|
10
|
+
spec.email = ["jan@mluv.cz"]
|
11
|
+
|
12
|
+
spec.summary = %q{JPEG and PNG compression processor for paperclip using MozJPEG.}
|
13
|
+
spec.description = %q{JPEG and PNG compression processor for paperclip using MozJPEG.}
|
14
|
+
spec.homepage = "https://github.com/svoboda-jan/paperclip-mozjpeg"
|
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.required_ruby_version = ">= 1.9"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.4.2"
|
27
|
+
|
28
|
+
spec.add_dependency "paperclip"
|
29
|
+
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-mozjpeg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Svoboda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.4.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.4.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: paperclip
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: JPEG and PNG compression processor for paperclip using MozJPEG.
|
70
|
+
email:
|
71
|
+
- jan@mluv.cz
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/paperclip-mozjpeg.rb
|
84
|
+
- lib/paperclip-mozjpeg/version.rb
|
85
|
+
- paperclip-mozjpeg.gemspec
|
86
|
+
homepage: https://github.com/svoboda-jan/paperclip-mozjpeg
|
87
|
+
licenses: []
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.9'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.4.6
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: JPEG and PNG compression processor for paperclip using MozJPEG.
|
109
|
+
test_files: []
|