polysize-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/lib/polysize/rails.rb +8 -0
- data/lib/polysize/rails/version.rb +5 -0
- data/vendor/assets/polysize.js +153 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 71be750c3a1cdaed0de89a429c6cdafe44c68969
|
4
|
+
data.tar.gz: 0f2df7dd9e8897662299fd6367905e15c3d3a0dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81508b53b136ca69933a18646f3a12302370799cb01b5ce889683260c0aedef85d5295b0e0139f781f852ea740cd87470232c45c4f1b8dc7b98cdfb9d45ea2d8
|
7
|
+
data.tar.gz: c174e4a95ae1da9e38f2cc9ae71cc01a4586bcad7e30926b027a921bf9c979678696e854b0c897ffc1db118c686939481100058e4e06a7c3888db44173ee1013
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Douglas Waltman II
|
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,28 @@
|
|
1
|
+
# Polysize::Rails
|
2
|
+
|
3
|
+
Add Polysize to your asset pipeline.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'polysize-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install polysize-rails
|
18
|
+
|
19
|
+
Then, require it in app.js
|
20
|
+
|
21
|
+
//= require 'polysize'
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Refer to the [polysize documentation](https://github.com/dw2/polysize)
|
26
|
+
|
27
|
+
## License
|
28
|
+
MIT
|
@@ -0,0 +1,153 @@
|
|
1
|
+
window.Polysize = (function() {
|
2
|
+
|
3
|
+
function Polysize(file, bounds) {
|
4
|
+
var options = {},
|
5
|
+
callback,
|
6
|
+
reader = new FileReader();
|
7
|
+
|
8
|
+
switch (arguments.length) {
|
9
|
+
case 4:
|
10
|
+
options = arguments[2];
|
11
|
+
callback = arguments[3];
|
12
|
+
break;
|
13
|
+
case 3:
|
14
|
+
callback = arguments[2];
|
15
|
+
break;
|
16
|
+
default:
|
17
|
+
return alert(
|
18
|
+
'Invalid function call. Polysize expects 3 or 4 arguments.');
|
19
|
+
}
|
20
|
+
if (typeof(bounds) == 'number') bounds = [bounds, bounds];
|
21
|
+
|
22
|
+
reader.onload = (function (f) { return function (e) {
|
23
|
+
var img = new Image();
|
24
|
+
|
25
|
+
img.onload = function (e) {
|
26
|
+
var canvas, ctx, data, w, h, x, y,
|
27
|
+
imgRatio = img.width / img.height,
|
28
|
+
newRatio = bounds[0] / bounds[1];
|
29
|
+
|
30
|
+
switch (typeof(options.sizing)) {
|
31
|
+
case 'object':
|
32
|
+
if (options.sizing.length !== 2) return alert(
|
33
|
+
"`sizing` must be a string or an array with 2 values.");
|
34
|
+
if (options.sizing[0] * options.sizing[1] === 0) return alert(
|
35
|
+
"`sizing` must have positive width and height.");
|
36
|
+
canvas = document.createElement('canvas');
|
37
|
+
canvas.width = options.sizing[0];
|
38
|
+
canvas.height = options.sizing[1];
|
39
|
+
ctx = canvas.getContext('2d');
|
40
|
+
ctx.imageSmoothingEnabled = true;
|
41
|
+
ctx.webkitImageSmoothingEnabled = true;
|
42
|
+
ctx.mozImageSmoothingEnabled = true;
|
43
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0,
|
44
|
+
options.sizing[0], options.sizing[1]);
|
45
|
+
img.src = canvas.toDataURL();
|
46
|
+
delete options.sizing;
|
47
|
+
return;
|
48
|
+
|
49
|
+
case 'string':
|
50
|
+
case 'undefined':
|
51
|
+
switch (options.sizing) {
|
52
|
+
case 'stretch':
|
53
|
+
w = bounds[0];
|
54
|
+
h = bounds[1];
|
55
|
+
break;
|
56
|
+
|
57
|
+
case 'fit':
|
58
|
+
if (imgRatio > newRatio) {
|
59
|
+
w = bounds[0];
|
60
|
+
h = img.height / img.width * bounds[1];
|
61
|
+
} else if (imgRatio < newRatio) {
|
62
|
+
w = img.width / img.height * bounds[0];
|
63
|
+
h = bounds[1];
|
64
|
+
} else {
|
65
|
+
w = bounds[0];
|
66
|
+
h = bounds[1];
|
67
|
+
}
|
68
|
+
break;
|
69
|
+
|
70
|
+
// crop by default
|
71
|
+
default:
|
72
|
+
if (imgRatio > newRatio) {
|
73
|
+
w = img.width / img.height * bounds[0];
|
74
|
+
h = bounds[1];
|
75
|
+
} else if (imgRatio < newRatio) {
|
76
|
+
w = bounds[0];
|
77
|
+
h = img.height / img.width * bounds[1];
|
78
|
+
} else {
|
79
|
+
w = bounds[0];
|
80
|
+
h = bounds[1];
|
81
|
+
}
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
break;
|
85
|
+
|
86
|
+
default:
|
87
|
+
return alert(
|
88
|
+
"Invalid option `sizing`. Must be a string or array.");
|
89
|
+
}
|
90
|
+
|
91
|
+
switch (typeof(options.origin)) {
|
92
|
+
case 'string':
|
93
|
+
switch (options.origin[0]) {
|
94
|
+
case 't':
|
95
|
+
y = 0;
|
96
|
+
break;
|
97
|
+
case 'c':
|
98
|
+
y = (bounds[1] - h) / 2;
|
99
|
+
break;
|
100
|
+
case 'b':
|
101
|
+
y = bounds[1] - h;
|
102
|
+
break;
|
103
|
+
default:
|
104
|
+
return alert(
|
105
|
+
"Invalid Polysize `origin` option.");
|
106
|
+
}
|
107
|
+
switch (options.origin[1]) {
|
108
|
+
case 'l':
|
109
|
+
x = 0;
|
110
|
+
break;
|
111
|
+
case 'c':
|
112
|
+
x = (bounds[0] - w) / 2;
|
113
|
+
break;
|
114
|
+
case 'r':
|
115
|
+
x = bounds[0] - w;
|
116
|
+
break;
|
117
|
+
default:
|
118
|
+
return alert(
|
119
|
+
"Invalid Polysize `origin` option.");
|
120
|
+
}
|
121
|
+
break;
|
122
|
+
|
123
|
+
case 'object':
|
124
|
+
return alert(
|
125
|
+
"`origin` of type `array` is not supported yet.");
|
126
|
+
|
127
|
+
default:
|
128
|
+
x = (bounds[0] - w) / 2;
|
129
|
+
y = (bounds[1] - h) / 2;
|
130
|
+
break;
|
131
|
+
}
|
132
|
+
|
133
|
+
canvas = document.createElement('canvas');
|
134
|
+
canvas.width = bounds[0];
|
135
|
+
canvas.height = bounds[1];
|
136
|
+
ctx = canvas.getContext('2d');
|
137
|
+
ctx.imageSmoothingEnabled = true;
|
138
|
+
ctx.webkitImageSmoothingEnabled = true;
|
139
|
+
ctx.mozImageSmoothingEnabled = true;
|
140
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, x, y, w, h);
|
141
|
+
img.src = canvas.toDataURL();
|
142
|
+
|
143
|
+
if (typeof(callback) === 'function') callback(img);
|
144
|
+
};
|
145
|
+
img.src = e.target.result;
|
146
|
+
|
147
|
+
}; })(file);
|
148
|
+
reader.readAsDataURL(file);
|
149
|
+
}
|
150
|
+
|
151
|
+
return Polysize;
|
152
|
+
|
153
|
+
})();
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polysize-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Douglas Waltman II
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.1'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- doug@dougwaltman.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- README.md
|
64
|
+
- lib/polysize/rails.rb
|
65
|
+
- lib/polysize/rails/version.rb
|
66
|
+
- vendor/assets/polysize.js
|
67
|
+
homepage: https://github.com/dw2/polysize-rails
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Add Polysize to your asset pipeline.
|
91
|
+
test_files: []
|