image_compressor_for_carrierwave 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 289f9896df67d40df5b27b6e1ae0819fad833173
|
4
|
+
data.tar.gz: c4d5ff27e60deb8d0005701f3ccbe3fd5eaa4dbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25e7622eeba3445b179bfb711a53a66c452862d52c781e1970a676636e415ccbdf45e3187594abf2a075ebc971644eeeec40b4888a7bb40a8e21327bf1695810
|
7
|
+
data.tar.gz: b6bfe308a1f2d4720d415291971a3a1f3ca07b3e649a67daf3a3b09d5adf32b81e3c2ef7173a420f30e7cdb90146d9fe763cb73d7f0a4425292c3f2733c527a0
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# image_compressor_for_carrierwave
|
2
2
|
|
3
|
+
Based on piet gem https://github.com/albertbellonch/piet (changed to use pngquantizer as default for PNG images),
|
3
4
|
On your CarrierWave uploader, include the extension:
|
4
5
|
|
5
6
|
```ruby
|
@@ -19,8 +20,10 @@ class ImageUploader < CarrierWave::Uploader::Base
|
|
19
20
|
end
|
20
21
|
```
|
21
22
|
|
22
|
-
passing parameters to encoders:
|
23
|
+
passing parameters to encoders only used for the jpeg compression:
|
23
24
|
|
24
25
|
```ruby
|
25
|
-
process optimize: [{ verbose: false, quality: 65
|
26
|
+
process optimize: [{ verbose: false, quality: 65 }]
|
26
27
|
```
|
28
|
+
|
29
|
+
Won't process images smaller than 500KB or as established in the ENV SKIP_COMPRESSION_IMAGE_FILE_IN_KB.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'image_compressor_for_carrierwave'
|
3
|
-
s.version = '1.0.
|
4
|
-
s.date = '2016-
|
3
|
+
s.version = '1.0.8'
|
4
|
+
s.date = '2016-12-12'
|
5
5
|
s.summary = "Image compressor to use with carrierwave uploaders"
|
6
6
|
s.description = "A simple image compression gem"
|
7
7
|
s.authors = ["Alejandro Fernandes Antunes"]
|
@@ -4,6 +4,7 @@ require 'image_compressor_for_carrierwave/carrierwave_extension'
|
|
4
4
|
module ImageCompressorForCarrierwave
|
5
5
|
class << self
|
6
6
|
def optimize(path, opts={})
|
7
|
+
return true if Rails.env.test?
|
7
8
|
output = optimize_for(path, opts)
|
8
9
|
puts output if opts[:verbose]
|
9
10
|
true
|
@@ -16,12 +17,23 @@ module ImageCompressorForCarrierwave
|
|
16
17
|
private
|
17
18
|
|
18
19
|
def optimize_for(path, opts)
|
20
|
+
human_size = number_to_human_size(File.open(path).size)
|
21
|
+
file_size_digit = human_size.to_i
|
22
|
+
file_size_unit = human_size.chomp[-2..-1]
|
23
|
+
|
24
|
+
return if skip_compression file_size_unit, file_size_digit
|
25
|
+
|
19
26
|
case mimetype(path)
|
20
|
-
|
21
|
-
|
27
|
+
when 'png', 'gif' then optimize_png(path, opts)
|
28
|
+
when 'jpeg' then optimize_jpg(path, opts)
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
32
|
+
def skip_compression(file_size_unit, file_size_digit)
|
33
|
+
return file_size_unit.downcase == 'kb' && file_size_digit <= 500 ||
|
34
|
+
file_size_digit <= ENV['SKIP_COMPRESSION_IMAGE_FILE_IN_KB'].to_i
|
35
|
+
end
|
36
|
+
|
25
37
|
def mimetype(path)
|
26
38
|
IO.popen(['file', '--brief', '--mime-type', path], in: :close, err: :close){|io| io.read.chomp.sub(/image\//, '')}
|
27
39
|
end
|
@@ -34,7 +46,7 @@ module ImageCompressorForCarrierwave
|
|
34
46
|
|
35
47
|
def optimize_jpg(path, opts)
|
36
48
|
quality = (0..100).include?(opts[:quality]) ? opts[:quality] : 100
|
37
|
-
vo = opts[:verbose] ?
|
49
|
+
vo = opts[:verbose] ? '-v' : '-q'
|
38
50
|
path.gsub!(/([\(\)\[\]\{\}\*\?\\])/, '\\\\\1')
|
39
51
|
`#{command_path("jpegoptim")} -f -m#{quality} --strip-all #{opts[:command_options]} #{vo} #{path}`
|
40
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_compressor_for_carrierwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alejandro Fernandes Antunes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: png_quantizator
|