paperclip-smusher 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/paperclip-smusher.rb +51 -0
- metadata +80 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module Paperclip
|
2
|
+
class Thumbnail < Processor
|
3
|
+
def make
|
4
|
+
src = @file
|
5
|
+
conv = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
|
6
|
+
conv.binmode
|
7
|
+
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
|
8
|
+
dst.binmode
|
9
|
+
|
10
|
+
begin
|
11
|
+
parameters = []
|
12
|
+
parameters << source_file_options
|
13
|
+
parameters << ":source"
|
14
|
+
parameters << transformation_command
|
15
|
+
parameters << convert_options
|
16
|
+
parameters << ":dest"
|
17
|
+
|
18
|
+
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
19
|
+
|
20
|
+
success = Paperclip.run("convert", parameters, :source => "#{File.expand_path(src.path)}[0]", :dest => File.expand_path(conv.path))
|
21
|
+
|
22
|
+
if conv.size > 0
|
23
|
+
format = begin
|
24
|
+
Paperclip.run("identify", "-format %m :file", :file => "#{File.expand_path(conv.path)}[0]")
|
25
|
+
rescue PaperclipCommandLineError
|
26
|
+
""
|
27
|
+
end
|
28
|
+
|
29
|
+
case format.strip
|
30
|
+
when 'JPEG'
|
31
|
+
# Part of libjpeg-progs deb package
|
32
|
+
success = Paperclip.run('jpegtran', "-copy none -optimize -perfect :source > :dest", :source => File.expand_path(conv.path), :dest => File.expand_path(dst.path))
|
33
|
+
when 'PNG'
|
34
|
+
success = Paperclip.run('pngcrush', "-rem alla -reduce -brute :source :dest", :source => File.expand_path(conv.path), :dest => File.expand_path(dst.path))
|
35
|
+
else
|
36
|
+
dst = conv
|
37
|
+
end
|
38
|
+
end
|
39
|
+
rescue Exception => e
|
40
|
+
Rails.logger.error "There was an error processing the thumbnail for #{@basename}. Check imagemagick, jpegtran and pngcrush installed."
|
41
|
+
|
42
|
+
HoptoadNotifier.notify(
|
43
|
+
:error_class => "Paperclip - images optimization",
|
44
|
+
:error_message => "Paperclip ERROR: #{e.message}"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
dst.size > 0 ? dst : conv
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-smusher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrea Salicetti
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-10 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: paperclip
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 11
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 4
|
32
|
+
version: "2.4"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: JPEG and PNG compression for Paperclip gem
|
36
|
+
email: andrea.salicetti@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/paperclip-smusher.rb
|
45
|
+
homepage: http://github.com/knightq/paperclip-smusher
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
requirements:
|
72
|
+
- jpegtran for JPEG compression
|
73
|
+
- optipng for PNG compression
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.15
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Image compression for Paperclip
|
79
|
+
test_files: []
|
80
|
+
|