retina_rails 0.0.6 → 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/README.md +5 -1
- data/lib/retina_rails/carrierwave.rb +19 -0
- data/lib/retina_rails/paperclip.rb +14 -0
- data/lib/retina_rails/version.rb +1 -1
- data/spec/carrierwave_spec.rb +30 -0
- data/spec/fixtures/db/retina_rails.sqlite3 +0 -0
- data/spec/paperclip_spec.rb +36 -7
- data/spec/support/schema.rb +1 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -28,12 +28,14 @@ class ExampleUploader < CarrierWave::Uploader::Base
|
|
28
28
|
|
29
29
|
version :small do
|
30
30
|
process :resize_to_fill => [30, 30]
|
31
|
+
process :retina_quality => 25
|
31
32
|
end
|
32
33
|
|
33
34
|
include RetinaRails::CarrierWave
|
34
35
|
|
35
36
|
end
|
36
37
|
```
|
38
|
+
By default it sets the retina image quality to 40 which can be overriden with `process :retina_quality => 25`
|
37
39
|
|
38
40
|
Paperclip
|
39
41
|
------------
|
@@ -47,12 +49,14 @@ class ExampleUploader < ActiveRecord::Base
|
|
47
49
|
:styles => {
|
48
50
|
:original => ["800x800", :jpg],
|
49
51
|
:big => ["125x125#", :jpg]
|
50
|
-
}
|
52
|
+
},
|
53
|
+
:retina_quality => 25
|
51
54
|
|
52
55
|
include RetinaRails::Paperclip
|
53
56
|
|
54
57
|
end
|
55
58
|
```
|
59
|
+
By default it sets the retina image quality to 40 which can be overriden by adding a `retina_quality` option
|
56
60
|
|
57
61
|
For retina images use
|
58
62
|
------------
|
@@ -33,13 +33,21 @@ module RetinaRails
|
|
33
33
|
version "#{v[0]}_retina" do
|
34
34
|
process dimensions_processor[0] => options
|
35
35
|
|
36
|
+
quality_processor = nil
|
37
|
+
|
36
38
|
## Set other processors
|
37
39
|
processors.each do |processor|
|
38
40
|
process processor[0] => processor[1]
|
41
|
+
|
42
|
+
quality_processor = true if processor[0] == :retina_quality
|
39
43
|
end
|
44
|
+
|
45
|
+
## Set default quality if retina_quality is not defined
|
46
|
+
process :retina_quality => 40 if quality_processor.nil?
|
40
47
|
end
|
41
48
|
|
42
49
|
end
|
50
|
+
|
43
51
|
end
|
44
52
|
|
45
53
|
end
|
@@ -51,6 +59,17 @@ module RetinaRails
|
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
62
|
+
## Set retina image quality
|
63
|
+
def retina_quality(percentage)
|
64
|
+
if version_name.to_s.include?('retina')
|
65
|
+
manipulate! do |img|
|
66
|
+
img.write(current_path) { self.quality = percentage } unless img.quality == percentage
|
67
|
+
img = yield(img) if block_given?
|
68
|
+
img
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
54
73
|
end
|
55
74
|
|
56
75
|
end
|
@@ -15,9 +15,14 @@ module RetinaRails
|
|
15
15
|
## Check for style definitions
|
16
16
|
styles = attachment_definitions[key][:styles]
|
17
17
|
|
18
|
+
## Get retina quality
|
19
|
+
retina_quality = attachment_definitions[key][:retina_quality] || 40
|
20
|
+
|
18
21
|
if styles
|
19
22
|
|
20
23
|
retina_styles = {}
|
24
|
+
retina_convert_options = {}
|
25
|
+
convert_options = attachment_definitions[key][:convert_options]
|
21
26
|
|
22
27
|
## Iterate over styles and set optimzed dimensions
|
23
28
|
styles.each_pair do |key, value|
|
@@ -31,11 +36,20 @@ module RetinaRails
|
|
31
36
|
|
32
37
|
retina_styles["#{key}_retina".to_sym] = ["#{width}x#{height}#{processor}", value[1]]
|
33
38
|
|
39
|
+
## Set quality convert option
|
40
|
+
convert_option = convert_options[key] if convert_options
|
41
|
+
convert_option = convert_option ? "#{convert_option} -quality #{retina_quality}" : "-quality #{retina_quality}"
|
42
|
+
retina_convert_options["#{key}_retina".to_sym] = convert_option
|
43
|
+
|
34
44
|
end
|
35
45
|
|
36
46
|
## Append new retina optimzed styles
|
37
47
|
value[:styles].merge!(retina_styles)
|
38
48
|
|
49
|
+
## Set quality convert options
|
50
|
+
value[:convert_options] = {} if value[:convert_options].nil?
|
51
|
+
value[:convert_options].merge!(retina_convert_options)
|
52
|
+
|
39
53
|
## Make path work with retina optimization
|
40
54
|
original_path = attachment_definitions[key][:path]
|
41
55
|
value[:path] = RetinaRails::Extensions.optimize_path(original_path) if original_path
|
data/lib/retina_rails/version.rb
CHANGED
data/spec/carrierwave_spec.rb
CHANGED
@@ -6,6 +6,12 @@ class AnonymousUploader < CarrierWave::Uploader::Base
|
|
6
6
|
|
7
7
|
version :small do
|
8
8
|
process :resize_to_fill => [30, 30]
|
9
|
+
process :quality => 60
|
10
|
+
process :retina_quality => 20
|
11
|
+
end
|
12
|
+
|
13
|
+
version :small_without_quality do
|
14
|
+
process :resize_to_fill => [30, 30]
|
9
15
|
end
|
10
16
|
|
11
17
|
version :small_without_dimensions do
|
@@ -23,6 +29,14 @@ class AnonymousUploader < CarrierWave::Uploader::Base
|
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
32
|
+
def quality(percentage)
|
33
|
+
manipulate! do |img|
|
34
|
+
img.write(current_path) { self.quality = percentage } unless img.quality == percentage
|
35
|
+
img = yield(img) if block_given?
|
36
|
+
img
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
26
40
|
version :small_without_processor
|
27
41
|
|
28
42
|
include RetinaRails::CarrierWave
|
@@ -75,6 +89,22 @@ describe RetinaRails::CarrierWave do
|
|
75
89
|
|
76
90
|
end
|
77
91
|
|
92
|
+
context 'with quality processor' do
|
93
|
+
|
94
|
+
it { Magick::Image.read(@uploader.small.current_path).first.quality.should == 60 }
|
95
|
+
|
96
|
+
it { Magick::Image.read(@uploader.small_retina.current_path).first.quality.should == 20 }
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'without quality processor' do
|
101
|
+
|
102
|
+
it { Magick::Image.read(@uploader.small_without_quality.current_path).first.quality.should == 84 }
|
103
|
+
|
104
|
+
it { Magick::Image.read(@uploader.small_without_quality_retina.current_path).first.quality.should == 40 }
|
105
|
+
|
106
|
+
end
|
107
|
+
|
78
108
|
context 'without dimensions processor' do
|
79
109
|
|
80
110
|
its(:versions) { should_not include :small_without_dimensions_retina }
|
Binary file
|
data/spec/paperclip_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
ROOT = File.dirname(__FILE__)
|
4
|
+
|
3
5
|
class PaperclipUpload < ActiveRecord::Base
|
4
6
|
|
5
7
|
has_attached_file :avatar,
|
@@ -7,8 +9,17 @@ class PaperclipUpload < ActiveRecord::Base
|
|
7
9
|
:original => ["800x800", :jpg],
|
8
10
|
:big => ["125x125#", :jpg]
|
9
11
|
},
|
10
|
-
:
|
11
|
-
:
|
12
|
+
:retina_quality => 60,
|
13
|
+
:path => "#{ROOT}/:class/:id/:basename_:style.:extension",
|
14
|
+
:url => "#{ROOT}/:class/:id/:basename_:style.:extension"
|
15
|
+
|
16
|
+
has_attached_file :avatar_without_quality,
|
17
|
+
:styles => {
|
18
|
+
:original => ["800x800", :jpg],
|
19
|
+
:big => ["125x125#", :jpg]
|
20
|
+
},
|
21
|
+
:path => "#{ROOT}/:class/:id/:basename_:style.:extension",
|
22
|
+
:url => "#{ROOT}/:class/:id/:basename_:style.:extension"
|
12
23
|
|
13
24
|
include RetinaRails::Paperclip
|
14
25
|
|
@@ -23,21 +34,39 @@ describe RetinaRails::Paperclip do
|
|
23
34
|
it { subject.attachment_definitions[:avatar][:styles][:original_retina].should == ['1600x1600', :jpg] }
|
24
35
|
it { subject.attachment_definitions[:avatar][:styles][:big_retina].should == ['250x250#', :jpg] }
|
25
36
|
|
26
|
-
it { subject.attachment_definitions[:avatar][:path].should == "#{
|
27
|
-
it { subject.attachment_definitions[:avatar][:url].should == "#{
|
37
|
+
it { subject.attachment_definitions[:avatar][:path].should == "#{ROOT}/:class/:id/:basename_:style:retina.:extension" }
|
38
|
+
it { subject.attachment_definitions[:avatar][:url].should == "#{ROOT}/:class/:id/:basename_:style:retina.:extension" }
|
28
39
|
|
29
40
|
end
|
30
41
|
|
31
42
|
context 'uploads' do
|
32
43
|
|
33
|
-
subject { PaperclipUpload.create(:avatar => File.open("#{
|
44
|
+
subject { PaperclipUpload.create(:avatar => File.open("#{ROOT}/fixtures/images/avatar.jpeg")) }
|
34
45
|
|
35
|
-
it { subject.avatar.url(:big).should == "#{
|
36
|
-
it { subject.avatar.url(:big_retina).should == "#{
|
46
|
+
it { subject.avatar.url(:big).should == "#{ROOT}/paperclip_uploads/1/avatar_big.jpg" }
|
47
|
+
it { subject.avatar.url(:big_retina).should == "#{ROOT}/paperclip_uploads/2/avatar_big@2x.jpg" }
|
37
48
|
|
38
49
|
it { Paperclip::Geometry.from_file(subject.avatar.url(:big)).to_s.should == '125x125' }
|
39
50
|
it { Paperclip::Geometry.from_file(subject.avatar.url(:big_retina)).to_s.should == '250x250' }
|
40
51
|
|
41
52
|
end
|
42
53
|
|
54
|
+
context 'with retina quality' do
|
55
|
+
|
56
|
+
subject { PaperclipUpload.create(:avatar => File.open("#{ROOT}/fixtures/images/avatar.jpeg")) }
|
57
|
+
|
58
|
+
it { Magick::Image.read(subject.avatar.url(:big)).first.quality.should == 84 }
|
59
|
+
it { Magick::Image.read(subject.avatar.url(:big_retina)).first.quality.should == 60 }
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'without retina quality' do
|
64
|
+
|
65
|
+
subject { PaperclipUpload.create(:avatar_without_quality => File.open("#{ROOT}/fixtures/images/avatar.jpeg")) }
|
66
|
+
|
67
|
+
it { Magick::Image.read(subject.avatar_without_quality.url(:big)).first.quality.should == 84 }
|
68
|
+
it { Magick::Image.read(subject.avatar_without_quality.url(:big_retina)).first.quality.should == 40 }
|
69
|
+
|
70
|
+
end
|
71
|
+
|
43
72
|
end
|
data/spec/support/schema.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retina_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|