carrierwave_imagevoodoo 0.0.4-java → 0.0.5-java
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.
- checksums.yaml +7 -0
- data/benchmarks/minimagick_vs_imagevoodoo.rb +8 -8
- data/lib/carrierwave_imagevoodoo/version.rb +1 -1
- data/lib/carrierwave_imagevoodoo.rb +37 -19
- data/spec/carrierwave_imagevoodoo_spec.rb +56 -23
- metadata +26 -52
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc64ea96e349a3c9d0c3a44c93f51a9621a59814
|
4
|
+
data.tar.gz: c37b4ec04cc4a1868003e4ca524e0bb799ebac0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4a2ffa1946c626a846cc2d68dd80bdff9af58c81d4b629d1f93f4292f76ea4393632156f9e27edbbd8ef7b994607b542cda1fbf3c6db595a02fbaca66d6baa1
|
7
|
+
data.tar.gz: c11739bc5e3db2d1925512b548f50db325c7ceea4304d6b4dcab6625f2f241a64bd5dfdc121897e6d9698415a8dd49cda84451bd5ace06a68d1f516b708f2915
|
@@ -4,10 +4,8 @@ require "carrierwave"
|
|
4
4
|
class CatUploader < CarrierWave::Uploader::Base
|
5
5
|
storage :file
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
process resize_to_fit: [200, 200]
|
10
|
-
end
|
7
|
+
version :thumbnail do
|
8
|
+
process resize_to_fit: [200, 200]
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
@@ -29,10 +27,12 @@ end
|
|
29
27
|
|
30
28
|
puts "STARTED"
|
31
29
|
3.times do
|
32
|
-
puts
|
33
|
-
|
34
|
-
|
30
|
+
puts(Benchmark.measure do
|
31
|
+
10.times do
|
32
|
+
instance.store! cat_file
|
35
33
|
|
36
|
-
|
34
|
+
FileUtils.rm_r "uploads"
|
35
|
+
end
|
36
|
+
end)
|
37
37
|
end
|
38
38
|
puts "ENDED"
|
@@ -11,9 +11,9 @@ module CarrierWave
|
|
11
11
|
process :convert => format
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def resize_to_limit width, height
|
15
|
+
process :resize_to_limit => [width, height]
|
16
|
+
end
|
17
17
|
|
18
18
|
def resize_to_fit width, height
|
19
19
|
process :resize_to_fit => [width, height]
|
@@ -35,22 +35,18 @@ module CarrierWave
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
def resize_to_limit width, height
|
39
|
+
manipulate! do |image|
|
40
|
+
if (width < image.width) || (height < image.height)
|
41
|
+
resize_to_fit!(image, width, height)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
40
45
|
|
41
46
|
def resize_to_fit width, height
|
42
47
|
manipulate! do |image|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
if width != cols or height != rows
|
47
|
-
scale = [width/cols.to_f, height/rows.to_f].min
|
48
|
-
cols = (scale * cols).round
|
49
|
-
rows = (scale * rows).round
|
50
|
-
image.resize cols, rows do |img|
|
51
|
-
yield(img) if block_given?
|
52
|
-
img.save current_path
|
53
|
-
end
|
48
|
+
if (width != image.width) || (height != image.height)
|
49
|
+
resize_to_fit!(image, width, height)
|
54
50
|
end
|
55
51
|
end
|
56
52
|
end
|
@@ -87,7 +83,7 @@ module CarrierWave
|
|
87
83
|
end
|
88
84
|
end
|
89
85
|
end
|
90
|
-
|
86
|
+
|
91
87
|
private
|
92
88
|
|
93
89
|
def extract_dimensions(width, height, new_width, new_height, type = :resize)
|
@@ -105,7 +101,7 @@ module CarrierWave
|
|
105
101
|
|
106
102
|
def extract_dimensions_for_crop(width, height, new_width, new_height)
|
107
103
|
extract_dimensions(width, height, new_width, new_height, :crop)
|
108
|
-
end
|
104
|
+
end
|
109
105
|
|
110
106
|
def extract_placement_for_crop(width, height, new_width, new_height)
|
111
107
|
x_offset = (width / 2.0) - (new_width / 2.0)
|
@@ -116,8 +112,30 @@ module CarrierWave
|
|
116
112
|
#def resize_and_pad width, height, background = :transparent
|
117
113
|
#end
|
118
114
|
|
115
|
+
def image_voodoo_image
|
116
|
+
@image_voodoo_image ||= ::ImageVoodoo.with_bytes(file.read)
|
117
|
+
end
|
118
|
+
|
119
119
|
def manipulate!
|
120
|
-
yield
|
120
|
+
yield image_voodoo_image
|
121
|
+
end
|
122
|
+
|
123
|
+
def resize_to_fit! image, width, height
|
124
|
+
w_ratio = width / image.width.to_f
|
125
|
+
h_ratio = height / image.height.to_f
|
126
|
+
ratio = [w_ratio, h_ratio].min
|
127
|
+
|
128
|
+
image.scale(ratio) do |img|
|
129
|
+
img.save current_path
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def width
|
134
|
+
image_voodoo_image.width
|
135
|
+
end
|
136
|
+
|
137
|
+
def height
|
138
|
+
image_voodoo_image.height
|
121
139
|
end
|
122
140
|
end
|
123
141
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe CarrierWave::ImageVoodoo do
|
4
4
|
let :klass do
|
@@ -7,47 +7,80 @@ describe CarrierWave::ImageVoodoo do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
subject do
|
11
11
|
klass.new
|
12
12
|
end
|
13
13
|
|
14
14
|
before do
|
15
|
-
FileUtils.cp(file_path(
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
FileUtils.cp(file_path("cat.jpg"), file_path("cat_copy.jpg"))
|
16
|
+
subject.stub(:file).and_return(File.new(file_path("cat_copy.jpg")))
|
17
|
+
subject.stub(:current_path).and_return(file_path("cat_copy.jpg"))
|
18
|
+
subject.stub(:cached?).and_return true
|
19
19
|
end
|
20
20
|
|
21
21
|
after do
|
22
|
-
FileUtils.rm(file_path(
|
22
|
+
FileUtils.rm(file_path("cat_copy.jpg"))
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
describe "#resize_to_fit" do
|
26
|
+
context "image is larger than dimensions" do
|
27
|
+
before { subject.resize_to_fit(200, 200) }
|
28
|
+
|
29
|
+
it { should have_dimensions(127, 200) }
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
context "image's largest side matches dimensions" do
|
33
|
+
before { subject.resize_to_fit(1000, 1000) }
|
34
|
+
|
35
|
+
it { should have_dimensions(635, 1000) }
|
34
36
|
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
context "image is upscaled if smaller than dimensions" do
|
39
|
+
before { subject.resize_to_fit(2000, 2000) }
|
40
|
+
|
41
|
+
it { should have_dimensions(1270, 2000) }
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
42
45
|
describe '#resize_to_fill' do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
context "image is exactly the same dimensions" do
|
47
|
+
before { subject.resize_to_fill(200, 200) }
|
48
|
+
|
49
|
+
it { should have_dimensions(200, 200) }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "image is scaled up if smaller than dimensions" do
|
53
|
+
before { subject.resize_to_fill(1000, 1000) }
|
54
|
+
|
55
|
+
it { should have_dimensions(1000, 1000) }
|
46
56
|
end
|
57
|
+
end
|
47
58
|
|
48
|
-
|
49
|
-
|
50
|
-
|
59
|
+
describe '#resize_to_limit' do
|
60
|
+
context "image fits within height constraints" do
|
61
|
+
before { subject.resize_to_limit(700, 200) }
|
62
|
+
|
63
|
+
it { should have_dimensions(127, 200) }
|
51
64
|
end
|
65
|
+
|
66
|
+
context "image fits within width constraints" do
|
67
|
+
before { subject.resize_to_limit(127, 2000) }
|
68
|
+
|
69
|
+
it { should have_dimensions(127, 200) }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "image does not scale up if smaller than dimensions" do
|
73
|
+
before { subject.resize_to_limit(2000, 2000) }
|
74
|
+
|
75
|
+
it { should have_dimensions(635, 1000) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#width" do
|
80
|
+
its(:width) { should == 635 }
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#height" do
|
84
|
+
its(:height) { should == 1000 }
|
52
85
|
end
|
53
86
|
end
|
metadata
CHANGED
@@ -1,100 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave_imagevoodoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: java
|
7
6
|
authors:
|
8
7
|
- Tasveer Singh
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: carrierwave
|
16
15
|
version_requirements: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- -
|
17
|
+
- - '>='
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
21
|
-
MA==
|
22
|
-
none: false
|
19
|
+
version: '0'
|
23
20
|
requirement: !ruby/object:Gem::Requirement
|
24
21
|
requirements:
|
25
|
-
- -
|
22
|
+
- - '>='
|
26
23
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
MA==
|
29
|
-
none: false
|
24
|
+
version: '0'
|
30
25
|
prerelease: false
|
31
26
|
type: :runtime
|
32
27
|
- !ruby/object:Gem::Dependency
|
33
28
|
name: image_voodoo
|
34
29
|
version_requirements: !ruby/object:Gem::Requirement
|
35
30
|
requirements:
|
36
|
-
- -
|
31
|
+
- - '>='
|
37
32
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
39
|
-
MA==
|
40
|
-
none: false
|
33
|
+
version: '0'
|
41
34
|
requirement: !ruby/object:Gem::Requirement
|
42
35
|
requirements:
|
43
|
-
- -
|
36
|
+
- - '>='
|
44
37
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
MA==
|
47
|
-
none: false
|
38
|
+
version: '0'
|
48
39
|
prerelease: false
|
49
40
|
type: :runtime
|
50
41
|
- !ruby/object:Gem::Dependency
|
51
42
|
name: activesupport
|
52
43
|
version_requirements: !ruby/object:Gem::Requirement
|
53
44
|
requirements:
|
54
|
-
- -
|
45
|
+
- - '>='
|
55
46
|
- !ruby/object:Gem::Version
|
56
47
|
version: 3.0.0
|
57
|
-
none: false
|
58
48
|
requirement: !ruby/object:Gem::Requirement
|
59
49
|
requirements:
|
60
|
-
- -
|
50
|
+
- - '>='
|
61
51
|
- !ruby/object:Gem::Version
|
62
52
|
version: 3.0.0
|
63
|
-
none: false
|
64
53
|
prerelease: false
|
65
54
|
type: :runtime
|
66
55
|
- !ruby/object:Gem::Dependency
|
67
56
|
name: rake
|
68
57
|
version_requirements: !ruby/object:Gem::Requirement
|
69
58
|
requirements:
|
70
|
-
- -
|
59
|
+
- - '>='
|
71
60
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
73
|
-
MA==
|
74
|
-
none: false
|
61
|
+
version: '0'
|
75
62
|
requirement: !ruby/object:Gem::Requirement
|
76
63
|
requirements:
|
77
|
-
- -
|
64
|
+
- - '>='
|
78
65
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
80
|
-
MA==
|
81
|
-
none: false
|
66
|
+
version: '0'
|
82
67
|
prerelease: false
|
83
68
|
type: :development
|
84
69
|
- !ruby/object:Gem::Dependency
|
85
70
|
name: rspec
|
86
71
|
version_requirements: !ruby/object:Gem::Requirement
|
87
72
|
requirements:
|
88
|
-
- -
|
73
|
+
- - '>='
|
89
74
|
- !ruby/object:Gem::Version
|
90
75
|
version: 2.12.0
|
91
|
-
none: false
|
92
76
|
requirement: !ruby/object:Gem::Requirement
|
93
77
|
requirements:
|
94
|
-
- -
|
78
|
+
- - '>='
|
95
79
|
- !ruby/object:Gem::Version
|
96
80
|
version: 2.12.0
|
97
|
-
none: false
|
98
81
|
prerelease: false
|
99
82
|
type: :development
|
100
83
|
description: CarrierWave support for ImageVoodoo
|
@@ -104,7 +87,7 @@ executables: []
|
|
104
87
|
extensions: []
|
105
88
|
extra_rdoc_files: []
|
106
89
|
files:
|
107
|
-
-
|
90
|
+
- .gitignore
|
108
91
|
- Gemfile
|
109
92
|
- LICENSE
|
110
93
|
- README.md
|
@@ -119,35 +102,26 @@ files:
|
|
119
102
|
- spec/spec_helper.rb
|
120
103
|
homepage: https://github.com/zenapsis/carrierwave_imagevoodoo
|
121
104
|
licenses: []
|
105
|
+
metadata: {}
|
122
106
|
post_install_message:
|
123
107
|
rdoc_options: []
|
124
108
|
require_paths:
|
125
109
|
- lib
|
126
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
127
111
|
requirements:
|
128
|
-
- -
|
112
|
+
- - '>='
|
129
113
|
- !ruby/object:Gem::Version
|
130
|
-
|
131
|
-
- 0
|
132
|
-
version: !binary |-
|
133
|
-
MA==
|
134
|
-
hash: 2
|
135
|
-
none: false
|
114
|
+
version: '0'
|
136
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
116
|
requirements:
|
138
|
-
- -
|
117
|
+
- - '>='
|
139
118
|
- !ruby/object:Gem::Version
|
140
|
-
|
141
|
-
- 0
|
142
|
-
version: !binary |-
|
143
|
-
MA==
|
144
|
-
hash: 2
|
145
|
-
none: false
|
119
|
+
version: '0'
|
146
120
|
requirements: []
|
147
121
|
rubyforge_project:
|
148
|
-
rubygems_version: 1.
|
122
|
+
rubygems_version: 2.1.9
|
149
123
|
signing_key:
|
150
|
-
specification_version:
|
124
|
+
specification_version: 4
|
151
125
|
summary: A simple CarrierWave processor utilizing ImageVoodoo for processing
|
152
126
|
test_files:
|
153
127
|
- spec/carrierwave_imagevoodoo_spec.rb
|