carrierwave-dimensions 0.0.1
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/.rvmrc +12 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/carrierwave_dimensions.gemspec +25 -0
- data/lib/carrierwave_dimensions.rb +4 -0
- data/lib/carrierwave_dimensions/processor.rb +39 -0
- data/lib/carrierwave_dimensions/version.rb +3 -0
- data/spec/data/mac-mini.png +0 -0
- data/spec/processor_spec.rb +54 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/carrierwave.rb +5 -0
- data/spec/support/env.rb +8 -0
- metadata +130 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
if ! rvm list | grep -q ruby-1.9.3-p194 ; then
|
4
|
+
rvm install 1.9.3-p194
|
5
|
+
fi
|
6
|
+
|
7
|
+
rvm 1.9.3-p194@ryantownsend_carrierwave_dimensions --create
|
8
|
+
|
9
|
+
if ! gem list | grep -q bundler ; then
|
10
|
+
gem install --no-ri --no-rdoc bundler
|
11
|
+
bundle install --without production
|
12
|
+
fi
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ryan Townsend
|
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,41 @@
|
|
1
|
+
# CarrierwaveDimensions
|
2
|
+
|
3
|
+
Stores the dimensions of an image when uploading. Individual versions can be stored with different columns in the database.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carrierwave-dimensions'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install carrierwave-dimensions
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
class MyUploader < CarrierWave::Uploader::Base
|
22
|
+
|
23
|
+
version :thumbnail do
|
24
|
+
process resize_to_fill: [500, 500]
|
25
|
+
process :store_dimensions
|
26
|
+
process :store_dimensions, columns: "thumbnail"
|
27
|
+
process :store_dimensions, {
|
28
|
+
width_column: "thumbnail_width",
|
29
|
+
height_column: "thumbnail_height"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/carrierwave_dimensions/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.authors = ["Ryan Townsend"]
|
6
|
+
s.email = ["ryan@ryantownsend.co.uk"]
|
7
|
+
s.description = %q{
|
8
|
+
Stores the dimensions of an image when uploading.
|
9
|
+
Individual versions can be stored with different columns in the database.
|
10
|
+
}
|
11
|
+
s.summary = %q{Stores the dimensions of an image when uploading}
|
12
|
+
s.homepage = "https://github.com/ryantownsend/carrierwave-dimensions"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split($\)
|
15
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
s.name = "carrierwave-dimensions"
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.version = CarrierwaveDimensions::VERSION
|
20
|
+
|
21
|
+
s.add_dependency "carrierwave"
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "mini_magick"
|
24
|
+
s.add_development_dependency "simplecov"
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "carrierwave"
|
2
|
+
|
3
|
+
module CarrierwaveDimensions
|
4
|
+
module Processor
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
base.send(:include, InstanceMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def store_dimensions(options = {})
|
12
|
+
process store_dimensions: options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
def store_dimensions(*args)
|
18
|
+
options = args.inject({}) do |result,arr|
|
19
|
+
result.merge(arr[0] => arr[1])
|
20
|
+
end
|
21
|
+
|
22
|
+
width_column = options[:width_column] ||
|
23
|
+
(options[:columns] && "#{options[:columns]}_width") ||
|
24
|
+
"#{mounted_as}_#{version_name || "default"}_width"
|
25
|
+
height_column = options[:height_column] ||
|
26
|
+
(options[:columns] && "#{options[:columns]}_height") ||
|
27
|
+
"#{mounted_as}_#{version_name || "default"}_height"
|
28
|
+
|
29
|
+
if model
|
30
|
+
width, height = `identify -format "%wx%h" #{file.path}`.split(/x/)
|
31
|
+
model.send("#{width_column}=", width.strip.to_i)
|
32
|
+
model.send("#{height_column}=", height.strip.to_i)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
CarrierWave::Uploader::Base.send(:include, CarrierwaveDimensions::Processor)
|
Binary file
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "../lib/carrierwave_dimensions/processor"
|
3
|
+
|
4
|
+
class TestUploader < CarrierWave::Uploader::Base
|
5
|
+
include CarrierWave::MiniMagick
|
6
|
+
|
7
|
+
process store_dimensions: {
|
8
|
+
width_column: :image_width,
|
9
|
+
height_column: :image_height
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
class UploadModel
|
14
|
+
attr_accessor :image_width, :image_height
|
15
|
+
end
|
16
|
+
|
17
|
+
describe CarrierwaveDimensions::Processor do
|
18
|
+
describe "processing images" do
|
19
|
+
subject do
|
20
|
+
TestUploader.new(model, :remote_file)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:model) { UploadModel.new }
|
24
|
+
let(:image_file) { nil }
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
TestUploader.enable_processing = true
|
28
|
+
subject.store!(File.open(image_file))
|
29
|
+
end
|
30
|
+
|
31
|
+
after(:each) do
|
32
|
+
subject.remove!
|
33
|
+
TestUploader.enable_processing = false
|
34
|
+
end
|
35
|
+
|
36
|
+
context "given a semi-transparent image" do
|
37
|
+
let(:image_file) do
|
38
|
+
File.new(File.join(File.dirname(__FILE__), "data/mac-mini.png"))
|
39
|
+
end
|
40
|
+
|
41
|
+
before(:each) do
|
42
|
+
subject.recreate_versions!
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set the width on the model" do
|
46
|
+
expect(subject.model.image_width).to eq 776
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should set the height on the model" do
|
50
|
+
expect(subject.model.image_height).to eq 325
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/support/env.rb
ADDED
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-dimensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Townsend
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: carrierwave
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
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: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
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: mini_magick
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
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
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! "\n Stores the dimensions of an image when uploading.\n Individual
|
79
|
+
versions can be stored with different columns in the database.\n "
|
80
|
+
email:
|
81
|
+
- ryan@ryantownsend.co.uk
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .rvmrc
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- carrierwave_dimensions.gemspec
|
93
|
+
- lib/carrierwave_dimensions.rb
|
94
|
+
- lib/carrierwave_dimensions/processor.rb
|
95
|
+
- lib/carrierwave_dimensions/version.rb
|
96
|
+
- spec/data/mac-mini.png
|
97
|
+
- spec/processor_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/support/carrierwave.rb
|
100
|
+
- spec/support/env.rb
|
101
|
+
homepage: https://github.com/ryantownsend/carrierwave-dimensions
|
102
|
+
licenses: []
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.8.24
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: Stores the dimensions of an image when uploading
|
125
|
+
test_files:
|
126
|
+
- spec/data/mac-mini.png
|
127
|
+
- spec/processor_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- spec/support/carrierwave.rb
|
130
|
+
- spec/support/env.rb
|