carrierwave-imagesorcery 0.0.2
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +100 -0
- data/Rakefile +10 -0
- data/carrierwave-imagesorcery.gemspec +24 -0
- data/lib/carrierwave-imagesorcery.rb +2 -0
- data/lib/carrierwave-imagesorcery/image_sorcery.rb +174 -0
- data/lib/carrierwave-imagesorcery/version.rb +5 -0
- data/spec/fixtures/landscape.jpg +0 -0
- data/spec/lib/carrierwave-imagesorcery/image_sorcery.rb +111 -0
- data/spec/lib/carrierwave-imagesorcery/image_sorcery_spec.rb +82 -0
- data/spec/spec_helper.rb +20 -0
- metadata +113 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 WaYdotNET
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# CarrierWave::ImageSorcery
|
2
|
+
|
3
|
+
Additional processing to use [ImageSorcery](https://github.com/EricR/image_sorcery) into [CarrierWave](https://github.com/jnicklas/carrierwave).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carrierwave-imagesorcery'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install carrierwave-imagesorcery
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To use those, you should include specified module (ImageSorcery) into your uploader and use processors:
|
22
|
+
|
23
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
24
|
+
include CarrierWave::ImageSorcery
|
25
|
+
.....
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
## Method implemented
|
30
|
+
|
31
|
+
convert
|
32
|
+
dimensions
|
33
|
+
resize_to_limit
|
34
|
+
resize_to_fit
|
35
|
+
resize_to_fill
|
36
|
+
resize_and_pad
|
37
|
+
|
38
|
+
## Example
|
39
|
+
|
40
|
+
class Uploader < CarrierWave::Uploader::Base
|
41
|
+
##
|
42
|
+
# Image manipulator library:
|
43
|
+
include CarrierWave::ImageSorcery
|
44
|
+
|
45
|
+
process :resize_and_pad => [900,300,"#ffeecc", 'South']
|
46
|
+
process :resize_to_fit => [1024, 768]
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
## Example custom method
|
51
|
+
|
52
|
+
An example to implement custom method
|
53
|
+
|
54
|
+
|
55
|
+
class Uploader < CarrierWave::Uploader::Base
|
56
|
+
include CarrierWave::ImageSorcery
|
57
|
+
process :watermark_text
|
58
|
+
|
59
|
+
def watermark_text(text = "© #{Time.now.year} - Carlo Bertini [WaYdotNET]")
|
60
|
+
manipulate! do |img|
|
61
|
+
args = {
|
62
|
+
font: 'Helvetica', fill: 'white', stroke: '#00770080',
|
63
|
+
gravity: 'South', pointsize: 20, draw: " text 0,0 \"#{text}\" "
|
64
|
+
}
|
65
|
+
img.manipulate! args
|
66
|
+
img
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
78
|
+
|
79
|
+
|
80
|
+
## Author
|
81
|
+
|
82
|
+
[](http://coderwall.com/waydotnet)
|
83
|
+
|
84
|
+
WaYdotNET, you can follow me on twitter [@WaYdotNET](http://twitter.com/WaYdotNET) or take a look at my site [waydotnet.com](http://www.waydotnet.com)
|
85
|
+
|
86
|
+
## Copyright
|
87
|
+
|
88
|
+
Copyright (C) 2012 Carlo Bertini - [@WaYdotNET](http://twitter.com/WaYdotNET)
|
89
|
+
|
90
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
91
|
+
associated documentation files (the “Software”), to deal in the Software without restriction, including without
|
92
|
+
limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
93
|
+
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
94
|
+
|
95
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
96
|
+
|
97
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
98
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM,
|
99
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
100
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/carrierwave-imagesorcery/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Carlo Bertini"]
|
6
|
+
gem.email = ["waydotnet@gmail.com"]
|
7
|
+
gem.description = "CarrierWave Additional processing to support ImageSorcery"
|
8
|
+
gem.summary = "ImageSorcery carrierwave processor"
|
9
|
+
gem.homepage = "http://www.waydotnet.com"
|
10
|
+
|
11
|
+
gem.extra_rdoc_files = ["README.md"]
|
12
|
+
gem.rdoc_options = ["--main"]
|
13
|
+
gem.add_development_dependency "rspec"
|
14
|
+
|
15
|
+
gem.add_dependency 'carrierwave'
|
16
|
+
gem.add_dependency 'image_sorcery'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($\)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.name = "carrierwave-imagesorcery"
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
gem.version = CarrierWave::ImageSorcery::VERSION
|
24
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'image_sorcery'
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module ImageSorcery
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def convert(format)
|
9
|
+
process :convert => format
|
10
|
+
end
|
11
|
+
|
12
|
+
def resize_to_limit(width, height)
|
13
|
+
process :resize_to_limit => [width, height]
|
14
|
+
end
|
15
|
+
|
16
|
+
def resize_to_fit(width, height)
|
17
|
+
process :resize_to_fit => [width, height]
|
18
|
+
end
|
19
|
+
|
20
|
+
def resize_to_fill(width, height, gravity='Center')
|
21
|
+
process :resize_to_fill => [width, height, gravity]
|
22
|
+
end
|
23
|
+
|
24
|
+
def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
|
25
|
+
process :resize_and_pad => [width, height, background, gravity]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Changes the image encoding format to the given format
|
31
|
+
#
|
32
|
+
# See http://www.imagemagick.org/script/command-line-options.php#format
|
33
|
+
#
|
34
|
+
# === Parameters
|
35
|
+
#
|
36
|
+
# [format (#to_s)] an abreviation of the format
|
37
|
+
#
|
38
|
+
#
|
39
|
+
# === Examples
|
40
|
+
#
|
41
|
+
# image.convert(:png)
|
42
|
+
#
|
43
|
+
def convert(format)
|
44
|
+
manipulate! do |img|
|
45
|
+
img.manipulate!(:format => format.to_s.downcase)
|
46
|
+
img = yield(img) if block_given?
|
47
|
+
img
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Resize the image to fit within the specified dimensions while retaining
|
53
|
+
# the original aspect ratio. Will only resize the image if it is larger than the
|
54
|
+
# specified dimensions. The resulting image may be shorter or narrower than specified
|
55
|
+
# in the smaller dimension but will not be larger than the specified values.
|
56
|
+
#
|
57
|
+
# === Parameters
|
58
|
+
#
|
59
|
+
# [width (Integer)] the width to scale the image to
|
60
|
+
# [height (Integer)] the height to scale the image to
|
61
|
+
#
|
62
|
+
def resize_to_limit(width, height)
|
63
|
+
manipulate! do |img|
|
64
|
+
img.manipulate!(:resize => "#{width}x#{height}>")
|
65
|
+
# img = yield(img) if block_given?
|
66
|
+
if img
|
67
|
+
img
|
68
|
+
else
|
69
|
+
raise CarrierWave::ProcessingError , I18n.translate(:"errors.messages.imagesorcery_processing_error")
|
70
|
+
end
|
71
|
+
# img
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Resize the image to fit within the specified dimensions while retaining
|
77
|
+
# the original aspect ratio. The image may be shorter or narrower than
|
78
|
+
# specified in the smaller dimension but will not be larger than the specified values.
|
79
|
+
#
|
80
|
+
# === Parameters
|
81
|
+
#
|
82
|
+
# [width (Integer)] the width to scale the image to
|
83
|
+
# [height (Integer)] the height to scale the image to
|
84
|
+
#
|
85
|
+
#
|
86
|
+
def resize_to_fit(width, height)
|
87
|
+
manipulate! do |img|
|
88
|
+
img.manipulate!(:resize => "#{width}x#{height}")
|
89
|
+
img = yield(img) if block_given?
|
90
|
+
if img
|
91
|
+
img
|
92
|
+
else
|
93
|
+
raise CarrierWave::ProcessingError , I18n.translate(:"errors.messages.imagesorcery_processing_error")
|
94
|
+
end
|
95
|
+
# img
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Resize the image to fit within the specified dimensions while retaining
|
101
|
+
# the aspect ratio of the original image. If necessary, crop the image in the
|
102
|
+
# larger dimension.
|
103
|
+
#
|
104
|
+
# === Parameters
|
105
|
+
#
|
106
|
+
# [width (Integer)] the width to scale the image to
|
107
|
+
# [height (Integer)] the height to scale the image to
|
108
|
+
# [gravity (String)] the current gravity suggestion (default: 'Center'; options: 'NorthWest', 'North', 'NorthEast', 'West', 'Center', 'East', 'SouthWest', 'South', 'SouthEast')
|
109
|
+
#
|
110
|
+
#
|
111
|
+
def resize_to_fill(width, height, gravity = 'Center')
|
112
|
+
manipulate! do |img|
|
113
|
+
cols, rows = img.dimensions[:x].to_i, img.dimensions[:y].to_i
|
114
|
+
opt={}
|
115
|
+
if width != cols || height != rows
|
116
|
+
scale = [width/cols.to_f, height/rows.to_f].max
|
117
|
+
cols = (scale * (cols + 0.5)).round
|
118
|
+
rows = (scale * (rows + 0.5)).round
|
119
|
+
opt[:resize] = "#{cols}x#{rows}"
|
120
|
+
end
|
121
|
+
opt[:gravity] = gravity
|
122
|
+
opt[:background] = "rgba(255,255,255,0.0)"
|
123
|
+
opt[:extent] = "#{width}x#{height}" if cols != width || rows != height
|
124
|
+
img.manipulate!(opt)
|
125
|
+
img = yield(img) if block_given?
|
126
|
+
img
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# Resize the image to fit within the specified dimensions while retaining
|
132
|
+
# the original aspect ratio. If necessary, will pad the remaining area
|
133
|
+
# with the given color, which defaults to transparent (for gif and png,
|
134
|
+
# white for jpeg).
|
135
|
+
#
|
136
|
+
# See http://www.imagemagick.org/script/command-line-options.php#gravity
|
137
|
+
# for gravity options.
|
138
|
+
#
|
139
|
+
# === Parameters
|
140
|
+
#
|
141
|
+
# [width (Integer)] the width to scale the image to
|
142
|
+
# [height (Integer)] the height to scale the image to
|
143
|
+
# [background (String, :transparent)] the color of the background as a hexcode, like "#ff45de"
|
144
|
+
# [gravity (String)] how to position the image
|
145
|
+
#
|
146
|
+
#
|
147
|
+
def resize_and_pad(width, height, background=:transparent, gravity='Center')
|
148
|
+
manipulate! do |img|
|
149
|
+
opt={}
|
150
|
+
opt[:thumbnail] = "#{width}x#{height}>"
|
151
|
+
background == :transparent ? opt[:background] = "rgba(255, 255, 255, 0.0)" : opt[:background] = background
|
152
|
+
opt[:gravity] = gravity
|
153
|
+
opt[:extent] = "#{width}x#{height}"
|
154
|
+
img.manipulate!(opt)
|
155
|
+
img = yield(img) if block_given?
|
156
|
+
img
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def dimensions
|
161
|
+
manipulate! do |img|
|
162
|
+
img.dimensions
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def manipulate!
|
167
|
+
cache_stored_file! if !cached?
|
168
|
+
image = Sorcery.new current_path
|
169
|
+
image = yield(image)
|
170
|
+
rescue RuntimeError, StandardError => e
|
171
|
+
raise CarrierWave::ProcessingError , I18n.translate(:"errors.messages.imagesorcery_processing_error", :e => e)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
Binary file
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# # require_relative '../../spec_helper'
|
2
|
+
# # For Ruby < 1.9.3, use this instead of require_relative
|
3
|
+
require (File.expand_path('./../../../spec_helper', __FILE__))
|
4
|
+
|
5
|
+
describe CarrierWave::ImageSorcery do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@klass = Class.new do
|
9
|
+
include CarrierWave::ImageSorcery
|
10
|
+
end
|
11
|
+
@instance = @klass.new
|
12
|
+
FileUtils.cp(file_path('landscape.jpg'), file_path('landscape_copy.jpg'))
|
13
|
+
@instance.stub(:current_path).and_return(file_path('landscape_copy.jpg'))
|
14
|
+
@instance.stub(:cached?).and_return true
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
FileUtils.rm(file_path('landscape_copy.jpg'))
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#convert" do
|
22
|
+
it "should convert from one format to another" do
|
23
|
+
@instance.convert('foo.png')
|
24
|
+
# img = ::MiniMagick::Image.open(@instance.current_path)
|
25
|
+
img = Sorcery.new @istance.current_path
|
26
|
+
identify= img.identify
|
27
|
+
identify.should =~ /PNG/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#resize_to_fill' do
|
32
|
+
it "should resize the image to exactly the given dimensions" do
|
33
|
+
@instance.resize_to_fill(200, 200)
|
34
|
+
@instance.should have_dimensions(200, 200)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
38
|
+
@instance.resize_to_fill(1000, 1000)
|
39
|
+
@instance.should have_dimensions(1000, 1000)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#resize_and_pad' do
|
44
|
+
it "should resize the image to exactly the given dimensions" do
|
45
|
+
@instance.resize_and_pad(200, 200)
|
46
|
+
@instance.should have_dimensions(200, 200)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
50
|
+
@instance.resize_and_pad(1000, 1000)
|
51
|
+
@instance.should have_dimensions(1000, 1000)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should pad with white" do
|
55
|
+
@instance.resize_and_pad(200, 200)
|
56
|
+
image = ::MiniMagick::Image.open(@instance.current_path)
|
57
|
+
x, y = 0, 0
|
58
|
+
color = image.run_command("convert", "#{image.escaped_path}[1x1+#{x}+#{y}]", "-depth 8", "txt:").split("\n")[1]
|
59
|
+
color.should include('#FFFFFF')
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#resize_to_fit' do
|
65
|
+
it "should resize the image to fit within the given dimensions" do
|
66
|
+
@instance.resize_to_fit(200, 200)
|
67
|
+
@instance.should have_dimensions(200, 150)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
71
|
+
@instance.resize_to_fit(1000, 1000)
|
72
|
+
@instance.should have_dimensions(1000, 750)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#resize_to_limit' do
|
77
|
+
it "should resize the image to fit within the given dimensions" do
|
78
|
+
@instance.resize_to_limit(200, 200)
|
79
|
+
@instance.should have_dimensions(200, 150)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should not scale up the image if it smaller than the given dimensions" do
|
83
|
+
@instance.resize_to_limit(1000, 1000)
|
84
|
+
@instance.should have_dimensions(640, 480)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "test errors" do
|
89
|
+
context "invalid image file" do
|
90
|
+
before do
|
91
|
+
File.open(@instance.current_path, 'w') do |f|
|
92
|
+
f.puts "bogus"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should fail to process a non image file" do
|
97
|
+
lambda {@instance.resize_to_limit(200, 200)}.should raise_exception(CarrierWave::ProcessingError, /^Failed to manipulate with MiniMagick, maybe it is not an image\? Original Error:/)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should use I18n" do
|
101
|
+
change_locale_and_store_translations(:nl, :errors => {
|
102
|
+
:messages => {
|
103
|
+
:mini_magick_processing_error => "Kon bestand niet met MiniMagick bewerken, misschien is het geen beeld bestand? MiniMagick foutmelding: %{e}"
|
104
|
+
}
|
105
|
+
}) do
|
106
|
+
lambda {@instance.resize_to_limit(200, 200)}.should raise_exception(CarrierWave::ProcessingError, /^Kon bestand niet met MiniMagick bewerken, misschien is het geen beeld bestand\? MiniMagick foutmelding:/)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# # require_relative '../../spec_helper'
|
2
|
+
# # For Ruby < 1.9.3, use this instead of require_relative
|
3
|
+
require (File.expand_path('./../../../spec_helper', __FILE__))
|
4
|
+
require 'subexec'
|
5
|
+
|
6
|
+
class Uploader < CarrierWave::Uploader::Base
|
7
|
+
include CarrierWave::ImageSorcery
|
8
|
+
end
|
9
|
+
|
10
|
+
describe CarrierWave::ImageSorcery do
|
11
|
+
|
12
|
+
before do
|
13
|
+
@klass = Class.new do
|
14
|
+
include CarrierWave::ImageSorcery
|
15
|
+
end
|
16
|
+
@instance = Uploader.new
|
17
|
+
FileUtils.cp(file_path('landscape.jpg'), file_path('landscape_copy.jpg'))
|
18
|
+
@instance.stub(:current_path).and_return(file_path('landscape_copy.jpg'))
|
19
|
+
@instance.stub(:cached?).and_return true
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
FileUtils.rm(file_path('landscape_copy.jpg'))
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#convert" do
|
27
|
+
it "should convert from one format to another" do
|
28
|
+
@instance.convert('foo.png')
|
29
|
+
img = Sorcery.new file_path('foo.png')
|
30
|
+
img.identify.should =~ /PNG/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#resize_to_fill' do
|
35
|
+
it "should resize the image to exactly the given dimensions" do
|
36
|
+
@instance.resize_to_fill(200, 200)
|
37
|
+
@instance.dimensions.should == check_dimension(200, 200)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
41
|
+
@instance.resize_to_fill(1000, 1000)
|
42
|
+
@instance.dimensions.should == check_dimension(1000, 1000)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#resize_and_pad' do
|
47
|
+
it "should resize the image to exactly the given dimensions" do
|
48
|
+
@instance.resize_and_pad(200, 200)
|
49
|
+
@instance.dimensions.should == check_dimension(200, 200)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
53
|
+
@instance.resize_and_pad(1000, 1000)
|
54
|
+
@instance.dimensions.should == check_dimension(1000, 1000)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#resize_to_fit' do
|
60
|
+
it "should resize the image to fit within the given dimensions" do
|
61
|
+
@instance.resize_to_fit(200, 200)
|
62
|
+
@instance.dimensions.should == check_dimension(200, 150)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should scale up the image if it smaller than the given dimensions" do
|
66
|
+
@instance.resize_to_fit(1000, 1000)
|
67
|
+
@instance.dimensions.should == check_dimension(1000, 750)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#resize_to_limit' do
|
72
|
+
it "should resize the image to fit within the given dimensions" do
|
73
|
+
@instance.resize_to_limit(200, 200)
|
74
|
+
@instance.dimensions.should == check_dimension(200, 150)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not scale up the image if it smaller than the given dimensions" do
|
78
|
+
@instance.resize_to_limit(1000, 1000)
|
79
|
+
@instance.dimensions.should == check_dimension(640, 480)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems' unless defined? Gem
|
2
|
+
# require 'minitest' if RUBY_VERSION < "1.9"
|
3
|
+
|
4
|
+
# we need the actual library file
|
5
|
+
# require_relative '../lib/ms_translate'
|
6
|
+
# For Ruby < 1.9.3, use this instead of require_relative
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'carrierwave'
|
9
|
+
|
10
|
+
require(File.expand_path('../../lib/carrierwave-imagesorcery', __FILE__))
|
11
|
+
require 'minitest/autorun'
|
12
|
+
|
13
|
+
|
14
|
+
def file_path(*paths)
|
15
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
16
|
+
end
|
17
|
+
|
18
|
+
def check_dimension(x, y)
|
19
|
+
{:x => "#{x}", :y => "#{y}"}
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-imagesorcery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Carlo Bertini
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: carrierwave
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: image_sorcery
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: CarrierWave Additional processing to support ImageSorcery
|
63
|
+
email:
|
64
|
+
- waydotnet@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files:
|
68
|
+
- README.md
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- carrierwave-imagesorcery.gemspec
|
76
|
+
- lib/carrierwave-imagesorcery.rb
|
77
|
+
- lib/carrierwave-imagesorcery/image_sorcery.rb
|
78
|
+
- lib/carrierwave-imagesorcery/version.rb
|
79
|
+
- spec/fixtures/landscape.jpg
|
80
|
+
- spec/lib/carrierwave-imagesorcery/image_sorcery.rb
|
81
|
+
- spec/lib/carrierwave-imagesorcery/image_sorcery_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
homepage: http://www.waydotnet.com
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options:
|
87
|
+
- --main
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.24
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: ImageSorcery carrierwave processor
|
108
|
+
test_files:
|
109
|
+
- spec/fixtures/landscape.jpg
|
110
|
+
- spec/lib/carrierwave-imagesorcery/image_sorcery.rb
|
111
|
+
- spec/lib/carrierwave-imagesorcery/image_sorcery_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
has_rdoc:
|