paperclip-compression 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/bin/linux/x64/jpegtran +0 -0
- data/bin/linux/x64/optipng +0 -0
- data/bin/linux/x86/jpegtran +0 -0
- data/bin/linux/x86/optipng +0 -0
- data/bin/osx/jpegtran +0 -0
- data/bin/osx/optipng +0 -0
- data/bin/win32/jpegtran.exe +0 -0
- data/bin/win32/libjpeg-62.dll +0 -0
- data/bin/win32/optipng.exe +0 -0
- data/bin/win64/jpegtran.exe +0 -0
- data/bin/win64/libjpeg-62.dll +0 -0
- data/lib/paperclip-compression/base.rb +48 -0
- data/lib/paperclip-compression/jpeg.rb +41 -0
- data/lib/paperclip-compression/paperclip/compression.rb +26 -0
- data/lib/paperclip-compression/png.rb +30 -0
- data/lib/paperclip-compression.rb +9 -92
- metadata +35 -12
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2M2ODg1OWIwNGQ1MDk2Mzg2YmYwNTgxNzA1ZDA4ZDA2NzNjMmQ3Yw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjZiNmI5YjcyMWFlMTFiZDg2ODZiY2M2MTU4Mzg3MTUyNWE5MDAyMg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZWFmNTJlNzliN2Y0OTc3NDU4ODgzNjdiMjFkMjE3NTkxOGNkOWRmNmM0ZTQy
|
10
|
+
YTNiMTQxYTI0NzVhMDAwNmJjZjliZDI2MjQxODk5NDMxZjdjNTBjMzVhZTg1
|
11
|
+
NmFhNmQ3ODc4ZTIyYWEwYWYyYjliZjNkOWQzZGRmNjMxNDNkNDA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTY2NzAwZTk5YzBkMWU1MDVjNTc3OWY4YjEyMDZhMzA3OWM4YTE0ZGZjODI3
|
14
|
+
YjMzNzJkNjQ1Yjc3M2RmODZkNDg2YjMzNjkzNzFiMjcxMzJjZmIzMzlkMmY4
|
15
|
+
MTFkNzg5OTQzMjAyNjk2ZTA5ZjlhMmZlNzg3OWM1ZDQxOWI5MGI=
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/bin/osx/jpegtran
ADDED
Binary file
|
data/bin/osx/optipng
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module PaperclipCompression
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def initialize(file, options = {})
|
5
|
+
@file = file
|
6
|
+
@options = options
|
7
|
+
@whiny = options.has_key?(:whiny) ? options[:whiny] : true
|
8
|
+
current_format = File.extname(file.path)
|
9
|
+
@basename = File.basename(file.path, current_format)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.make(file, options = {})
|
13
|
+
new(file, options).make
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def init_cli_opts(type, default_opts)
|
19
|
+
processor_opts = @options[:processor_options]
|
20
|
+
if processor_opts && (compression_opts = processor_opts[:compression])
|
21
|
+
if compression_opts.has_key?(type)
|
22
|
+
if (type_opts = compression_opts[type])
|
23
|
+
type_opts.kind_of?(String) ? type_opts : default_opts
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
else
|
28
|
+
default_opts
|
29
|
+
end
|
30
|
+
else
|
31
|
+
default_opts
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def command_path(command)
|
36
|
+
folder = if OS.osx?
|
37
|
+
'osx'
|
38
|
+
elsif OS.linux?
|
39
|
+
File.join('linux', OS.bits.eql?(64) ? 'x64' : 'x86')
|
40
|
+
elsif OS.windows?
|
41
|
+
OS.bits.eql?(64) ? 'win64' : 'win32'
|
42
|
+
end
|
43
|
+
|
44
|
+
File.join(PaperclipCompression.root, 'bin', folder, command)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module PaperclipCompression
|
2
|
+
class Jpeg < Base
|
3
|
+
|
4
|
+
JPEGTRAN_DEFAULT_OPTS = '-copy none -optimize -perfect'
|
5
|
+
|
6
|
+
def initialize(file, options = {})
|
7
|
+
super(file, options)
|
8
|
+
|
9
|
+
format = options[:format]
|
10
|
+
@dst = Tempfile.new([@basename, format ? ".#{format}" : ''])
|
11
|
+
@dst.binmode
|
12
|
+
|
13
|
+
@src_path = File.expand_path(@file.path)
|
14
|
+
@dst_path = File.expand_path(@dst.path)
|
15
|
+
|
16
|
+
@cli_opts = init_cli_opts(:jpeg, default_opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
def make
|
20
|
+
begin
|
21
|
+
if @cli_opts
|
22
|
+
Paperclip.run(command_path('jpegtran'), "#{@cli_opts} :src_path > :dst_path", src_path: @src_path, dst_path: @dst_path)
|
23
|
+
@dst
|
24
|
+
else
|
25
|
+
@file
|
26
|
+
end
|
27
|
+
rescue Cocaine::ExitStatusError => e
|
28
|
+
raise Paperclip::Error, "JPEGTRAN : There was an error processing the thumbnail for #{@basename}" if @whiny
|
29
|
+
rescue Cocaine::CommandNotFoundError => e
|
30
|
+
raise Paperclip::Errors::CommandNotFoundError.new("Could not run 'jpegtran'. Please install jpegtran.")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def default_opts
|
37
|
+
JPEGTRAN_DEFAULT_OPTS
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Paperclip
|
2
|
+
# Compresses the JPEG and PNG files
|
3
|
+
class Compression < Processor
|
4
|
+
|
5
|
+
def make
|
6
|
+
case @attachment.content_type
|
7
|
+
when 'image/jpeg' then make_jpeg
|
8
|
+
when 'image/png' then make_png
|
9
|
+
else
|
10
|
+
@file
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def make_jpeg
|
17
|
+
PaperclipCompression::Jpeg.make(@file, @options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def make_png
|
21
|
+
PaperclipCompression::Png.make(@file, @options)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PaperclipCompression
|
2
|
+
class Png < Base
|
3
|
+
|
4
|
+
OPTIPNG_DEFAULT_OPTS = '-o 5'
|
5
|
+
|
6
|
+
def initialize(file, options = {})
|
7
|
+
super(file, options)
|
8
|
+
@src_path = File.expand_path(@file.path)
|
9
|
+
@cli_opts = init_cli_opts(:png, default_opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def make
|
13
|
+
begin
|
14
|
+
Paperclip.run(command_path('optipng'), "#{@cli_opts} :src_path", src_path: @src_path) if @cli_opts
|
15
|
+
@file
|
16
|
+
rescue Cocaine::ExitStatusError => e
|
17
|
+
raise Paperclip::Error, "OPTIPNG : There was an error processing the thumbnail for #{@basename}" if @whiny
|
18
|
+
rescue Cocaine::CommandNotFoundError => e
|
19
|
+
raise Paperclip::Errors::CommandNotFoundError.new("Could not run 'optipng'. Please install optipng.")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def default_opts
|
26
|
+
OPTIPNG_DEFAULT_OPTS
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -1,95 +1,12 @@
|
|
1
1
|
require 'paperclip'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(file, options = {}, attachment = nil)
|
13
|
-
super
|
14
|
-
@format = options[:format]
|
15
|
-
@current_format = File.extname(@file.path)
|
16
|
-
@basename = File.basename(@file.path, @current_format)
|
17
|
-
|
18
|
-
if @options[:processor_options] && (compression_opts = @options[:processor_options][:compression])
|
19
|
-
|
20
|
-
@jpegtran_opts = if compression_opts.has_key?(:jpeg)
|
21
|
-
if (jpeg_opts = compression_opts[:jpeg])
|
22
|
-
jpeg_opts.kind_of?(String) ? jpeg_opts : JPEGTRAN_DEFAULT_OPTS
|
23
|
-
else
|
24
|
-
false
|
25
|
-
end
|
26
|
-
else
|
27
|
-
JPEGTRAN_DEFAULT_OPTS
|
28
|
-
end
|
29
|
-
|
30
|
-
@optipng_opts = if compression_opts.has_key?(:png)
|
31
|
-
if (png_opts = compression_opts[:png])
|
32
|
-
png_opts.kind_of?(String) ? png_opts : OPTIPNG_DEFAULT_OPTS
|
33
|
-
else
|
34
|
-
false
|
35
|
-
end
|
36
|
-
else
|
37
|
-
OPTIPNG_DEFAULT_OPTS
|
38
|
-
end
|
39
|
-
|
40
|
-
else
|
41
|
-
@jpegtran_opts = JPEGTRAN_DEFAULT_OPTS
|
42
|
-
@optipng_opts = OPTIPNG_DEFAULT_OPTS
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def make
|
47
|
-
case @attachment.content_type
|
48
|
-
when 'image/jpeg' then process_jpegtran
|
49
|
-
when 'image/png' then process_optipgn
|
50
|
-
else
|
51
|
-
@file
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def process_jpegtran
|
58
|
-
src = @file
|
59
|
-
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
|
60
|
-
dst.binmode
|
61
|
-
|
62
|
-
src_path = File.expand_path(src.path)
|
63
|
-
dst_path = File.expand_path(dst.path)
|
64
|
-
|
65
|
-
begin
|
66
|
-
if @jpegtran_opts
|
67
|
-
Paperclip.run('jpegtran', "#{@jpegtran_opts} '#{src_path}' > '#{dst_path}'")
|
68
|
-
dst
|
69
|
-
else
|
70
|
-
src
|
71
|
-
end
|
72
|
-
rescue Cocaine::ExitStatusError => e
|
73
|
-
raise Paperclip::Error, "JPEGTRAN : There was an error processing the thumbnail for #{@basename}" if @whiny
|
74
|
-
rescue Cocaine::CommandNotFoundError => e
|
75
|
-
raise Paperclip::Errors::CommandNotFoundError.new("Could not run 'jpegtran'.Please install jpegtran.")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def process_optipgn
|
80
|
-
src = @file
|
81
|
-
src_path = File.expand_path(src.path)
|
82
|
-
|
83
|
-
begin
|
84
|
-
Paperclip.run('optipng', "#{@optipng_opts} '#{src_path}'") if @optipng_opts
|
85
|
-
src
|
86
|
-
rescue Cocaine::ExitStatusError => e
|
87
|
-
raise Paperclip::Error, "OPTIPNG : There was an error processing the thumbnail for #{@basename}" if @whiny
|
88
|
-
rescue Cocaine::CommandNotFoundError => e
|
89
|
-
raise Paperclip::Errors::CommandNotFoundError.new("Could not run 'optipng'.Please install optipng.")
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
2
|
+
require 'os'
|
3
|
+
require 'paperclip-compression/paperclip/compression'
|
4
|
+
require 'paperclip-compression/base'
|
5
|
+
require 'paperclip-compression/jpeg'
|
6
|
+
require 'paperclip-compression/png'
|
7
|
+
|
8
|
+
module PaperclipCompression
|
9
|
+
def self.root
|
10
|
+
Gem::Specification.find_by_name('paperclip-compression').gem_dir
|
93
11
|
end
|
94
|
-
|
95
12
|
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-compression
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- İ. Emre Kutlu
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: paperclip
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,42 +20,67 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '3.3'
|
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
|
30
41
|
description: JPEG and PNG compression for Paperclip gem
|
31
42
|
email: emrekutlu@gmail.com
|
32
43
|
executables: []
|
33
44
|
extensions: []
|
34
45
|
extra_rdoc_files: []
|
35
46
|
files:
|
47
|
+
- lib/paperclip-compression/base.rb
|
48
|
+
- lib/paperclip-compression/jpeg.rb
|
49
|
+
- lib/paperclip-compression/paperclip/compression.rb
|
50
|
+
- lib/paperclip-compression/png.rb
|
36
51
|
- lib/paperclip-compression.rb
|
52
|
+
- bin/linux/x64/jpegtran
|
53
|
+
- bin/linux/x64/optipng
|
54
|
+
- bin/linux/x86/jpegtran
|
55
|
+
- bin/linux/x86/optipng
|
56
|
+
- bin/osx/jpegtran
|
57
|
+
- bin/osx/optipng
|
58
|
+
- bin/win32/jpegtran.exe
|
59
|
+
- bin/win32/libjpeg-62.dll
|
60
|
+
- bin/win32/optipng.exe
|
61
|
+
- bin/win64/jpegtran.exe
|
62
|
+
- bin/win64/libjpeg-62.dll
|
37
63
|
homepage: http://github.com/emrekutlu/paperclip-compression
|
38
64
|
licenses: []
|
65
|
+
metadata: {}
|
39
66
|
post_install_message:
|
40
67
|
rdoc_options: []
|
41
68
|
require_paths:
|
42
69
|
- lib
|
43
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
71
|
requirements:
|
46
72
|
- - ! '>='
|
47
73
|
- !ruby/object:Gem::Version
|
48
74
|
version: '0'
|
49
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
76
|
requirements:
|
52
77
|
- - ! '>='
|
53
78
|
- !ruby/object:Gem::Version
|
54
79
|
version: '0'
|
55
|
-
requirements:
|
56
|
-
- jpegtran for JPEG compression
|
57
|
-
- optipng for PNG compression
|
80
|
+
requirements: []
|
58
81
|
rubyforge_project:
|
59
|
-
rubygems_version:
|
82
|
+
rubygems_version: 2.0.3
|
60
83
|
signing_key:
|
61
|
-
specification_version:
|
84
|
+
specification_version: 4
|
62
85
|
summary: Image compression for Paperclip
|
63
86
|
test_files: []
|