blueimp-load-image-rails 1.8.0 → 1.9.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.
- checksums.yaml +4 -4
- data/{vendor → app}/assets/javascripts/blueimp-load-image.js +1 -0
- data/{vendor → app}/assets/javascripts/load-image-exif-map.js +0 -0
- data/{vendor → app}/assets/javascripts/load-image-exif.js +0 -0
- data/{vendor → app}/assets/javascripts/load-image-ios.js +20 -13
- data/{vendor → app}/assets/javascripts/load-image-meta.js +0 -0
- data/app/assets/javascripts/load-image-orientation.js +159 -0
- data/{vendor → app}/assets/javascripts/load-image.js +71 -84
- data/lib/blueimp-load-image-rails/version.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb9643e780934f976c80f31783a97f58ea7e81a
|
4
|
+
data.tar.gz: 1465e3a4a2d1692d513325f1e3975127e19e021d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35b880d2320a6c96ed59c5a72719fb0797ad289a0b3c398879eb06654ee7c0b07c59b8cd9bd7999ec2be65ceac216b343a64b4f157fdb1864ce31d9ba4ede4a9
|
7
|
+
data.tar.gz: 98e7eff6674aff85875affcd77c9a1bba150d78dfff2aff5e165d4aaf14bd583c86b077ae85235e3b0258812500cabba4f000ddfd4e53f91d4ef5e943e6da1cd
|
File without changes
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* JavaScript Load Image iOS scaling fixes 1.0.
|
2
|
+
* JavaScript Load Image iOS scaling fixes 1.0.3
|
3
3
|
* https://github.com/blueimp/JavaScript-Load-Image
|
4
4
|
*
|
5
5
|
* Copyright 2013, Sebastian Tschan
|
@@ -53,22 +53,26 @@
|
|
53
53
|
};
|
54
54
|
|
55
55
|
// Detects vertical squash in JPEG images:
|
56
|
-
loadImage.detectVerticalSquash = function (img,
|
57
|
-
var
|
56
|
+
loadImage.detectVerticalSquash = function (img, subsampled) {
|
57
|
+
var naturalHeight = img.naturalHeight || img.height,
|
58
|
+
canvas = document.createElement('canvas'),
|
58
59
|
context = canvas.getContext('2d'),
|
59
60
|
data,
|
60
61
|
sy,
|
61
62
|
ey,
|
62
63
|
py,
|
63
64
|
alpha;
|
65
|
+
if (subsampled) {
|
66
|
+
naturalHeight /= 2;
|
67
|
+
}
|
64
68
|
canvas.width = 1;
|
65
|
-
canvas.height =
|
69
|
+
canvas.height = naturalHeight;
|
66
70
|
context.drawImage(img, 0, 0);
|
67
|
-
data = context.getImageData(0, 0, 1,
|
71
|
+
data = context.getImageData(0, 0, 1, naturalHeight).data;
|
68
72
|
// search image edge pixel position in case it is squashed vertically:
|
69
73
|
sy = 0;
|
70
|
-
ey =
|
71
|
-
py =
|
74
|
+
ey = naturalHeight;
|
75
|
+
py = naturalHeight;
|
72
76
|
while (py > sy) {
|
73
77
|
alpha = data[(py - 1) * 4 + 3];
|
74
78
|
if (alpha === 0) {
|
@@ -78,7 +82,7 @@
|
|
78
82
|
}
|
79
83
|
py = (ey + sy) >> 1;
|
80
84
|
}
|
81
|
-
return (py /
|
85
|
+
return (py / naturalHeight) || 1;
|
82
86
|
};
|
83
87
|
|
84
88
|
// Renders image to canvas while working around iOS image scaling bugs:
|
@@ -100,20 +104,23 @@
|
|
100
104
|
tmpCanvas = document.createElement('canvas'),
|
101
105
|
tileSize = 1024,
|
102
106
|
tmpContext = tmpCanvas.getContext('2d'),
|
103
|
-
|
107
|
+
subsampled,
|
104
108
|
vertSquashRatio,
|
105
109
|
tileX,
|
106
110
|
tileY;
|
107
111
|
tmpCanvas.width = tileSize;
|
108
112
|
tmpCanvas.height = tileSize;
|
109
113
|
context.save();
|
110
|
-
|
111
|
-
if (
|
114
|
+
subsampled = loadImage.detectSubsampling(img);
|
115
|
+
if (subsampled) {
|
116
|
+
sourceX /= 2;
|
117
|
+
sourceY /= 2;
|
112
118
|
sourceWidth /= 2;
|
113
119
|
sourceHeight /= 2;
|
114
120
|
}
|
115
|
-
vertSquashRatio = loadImage.detectVerticalSquash(img,
|
116
|
-
if (
|
121
|
+
vertSquashRatio = loadImage.detectVerticalSquash(img, subsampled);
|
122
|
+
if (subsampled || vertSquashRatio !== 1) {
|
123
|
+
sourceY *= vertSquashRatio;
|
117
124
|
destWidth = Math.ceil(tileSize * destWidth / sourceWidth);
|
118
125
|
destHeight = Math.ceil(
|
119
126
|
tileSize * destHeight / sourceHeight / vertSquashRatio
|
File without changes
|
@@ -0,0 +1,159 @@
|
|
1
|
+
/*
|
2
|
+
* JavaScript Load Image Orientation 1.0.0
|
3
|
+
* https://github.com/blueimp/JavaScript-Load-Image
|
4
|
+
*
|
5
|
+
* Copyright 2013, Sebastian Tschan
|
6
|
+
* https://blueimp.net
|
7
|
+
*
|
8
|
+
* Licensed under the MIT license:
|
9
|
+
* http://www.opensource.org/licenses/MIT
|
10
|
+
*/
|
11
|
+
|
12
|
+
/*global define, window */
|
13
|
+
|
14
|
+
(function (factory) {
|
15
|
+
'use strict';
|
16
|
+
if (typeof define === 'function' && define.amd) {
|
17
|
+
// Register as an anonymous AMD module:
|
18
|
+
define(['load-image'], factory);
|
19
|
+
} else {
|
20
|
+
// Browser globals:
|
21
|
+
factory(window.loadImage);
|
22
|
+
}
|
23
|
+
}(function (loadImage) {
|
24
|
+
'use strict';
|
25
|
+
|
26
|
+
var originalHasCanvasOptionMethod = loadImage.hasCanvasOption;
|
27
|
+
|
28
|
+
// This method is used to determine if the target image
|
29
|
+
// should be a canvas element:
|
30
|
+
loadImage.hasCanvasOption = function (options) {
|
31
|
+
return originalHasCanvasOptionMethod(options) || options.orientation;
|
32
|
+
};
|
33
|
+
|
34
|
+
// Transform image orientation based on
|
35
|
+
// the given EXIF orientation option:
|
36
|
+
loadImage.transformCoordinates = function (canvas, options) {
|
37
|
+
var ctx = canvas.getContext('2d'),
|
38
|
+
width = canvas.width,
|
39
|
+
height = canvas.height,
|
40
|
+
orientation = options.orientation;
|
41
|
+
if (!orientation) {
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
if (orientation > 4) {
|
45
|
+
canvas.width = height;
|
46
|
+
canvas.height = width;
|
47
|
+
}
|
48
|
+
switch (orientation) {
|
49
|
+
case 2:
|
50
|
+
// horizontal flip
|
51
|
+
ctx.translate(width, 0);
|
52
|
+
ctx.scale(-1, 1);
|
53
|
+
break;
|
54
|
+
case 3:
|
55
|
+
// 180° rotate left
|
56
|
+
ctx.translate(width, height);
|
57
|
+
ctx.rotate(Math.PI);
|
58
|
+
break;
|
59
|
+
case 4:
|
60
|
+
// vertical flip
|
61
|
+
ctx.translate(0, height);
|
62
|
+
ctx.scale(1, -1);
|
63
|
+
break;
|
64
|
+
case 5:
|
65
|
+
// vertical flip + 90 rotate right
|
66
|
+
ctx.rotate(0.5 * Math.PI);
|
67
|
+
ctx.scale(1, -1);
|
68
|
+
break;
|
69
|
+
case 6:
|
70
|
+
// 90° rotate right
|
71
|
+
ctx.rotate(0.5 * Math.PI);
|
72
|
+
ctx.translate(0, -height);
|
73
|
+
break;
|
74
|
+
case 7:
|
75
|
+
// horizontal flip + 90 rotate right
|
76
|
+
ctx.rotate(0.5 * Math.PI);
|
77
|
+
ctx.translate(width, -height);
|
78
|
+
ctx.scale(-1, 1);
|
79
|
+
break;
|
80
|
+
case 8:
|
81
|
+
// 90° rotate left
|
82
|
+
ctx.rotate(-0.5 * Math.PI);
|
83
|
+
ctx.translate(-width, 0);
|
84
|
+
break;
|
85
|
+
}
|
86
|
+
};
|
87
|
+
|
88
|
+
// Transforms coordinate and dimension options
|
89
|
+
// based on the given orientation option:
|
90
|
+
loadImage.getTransformedOptions = function (options) {
|
91
|
+
if (!options.orientation || options.orientation === 1) {
|
92
|
+
return options;
|
93
|
+
}
|
94
|
+
var newOptions = {},
|
95
|
+
i;
|
96
|
+
for (i in options) {
|
97
|
+
if (options.hasOwnProperty(i)) {
|
98
|
+
newOptions[i] = options[i];
|
99
|
+
}
|
100
|
+
}
|
101
|
+
switch (options.orientation) {
|
102
|
+
case 2:
|
103
|
+
// horizontal flip
|
104
|
+
newOptions.left = options.right;
|
105
|
+
newOptions.right = options.left;
|
106
|
+
break;
|
107
|
+
case 3:
|
108
|
+
// 180° rotate left
|
109
|
+
newOptions.left = options.right;
|
110
|
+
newOptions.top = options.bottom;
|
111
|
+
newOptions.right = options.left;
|
112
|
+
newOptions.bottom = options.top;
|
113
|
+
break;
|
114
|
+
case 4:
|
115
|
+
// vertical flip
|
116
|
+
newOptions.top = options.bottom;
|
117
|
+
newOptions.bottom = options.top;
|
118
|
+
break;
|
119
|
+
case 5:
|
120
|
+
// vertical flip + 90 rotate right
|
121
|
+
newOptions.left = options.top;
|
122
|
+
newOptions.top = options.left;
|
123
|
+
newOptions.right = options.bottom;
|
124
|
+
newOptions.bottom = options.right;
|
125
|
+
break;
|
126
|
+
case 6:
|
127
|
+
// 90° rotate right
|
128
|
+
newOptions.left = options.top;
|
129
|
+
newOptions.top = options.right;
|
130
|
+
newOptions.right = options.bottom;
|
131
|
+
newOptions.bottom = options.left;
|
132
|
+
break;
|
133
|
+
case 7:
|
134
|
+
// horizontal flip + 90 rotate right
|
135
|
+
newOptions.left = options.bottom;
|
136
|
+
newOptions.top = options.right;
|
137
|
+
newOptions.right = options.top;
|
138
|
+
newOptions.bottom = options.left;
|
139
|
+
break;
|
140
|
+
case 8:
|
141
|
+
// 90° rotate left
|
142
|
+
newOptions.left = options.bottom;
|
143
|
+
newOptions.top = options.left;
|
144
|
+
newOptions.right = options.top;
|
145
|
+
newOptions.bottom = options.right;
|
146
|
+
break;
|
147
|
+
}
|
148
|
+
if (options.orientation > 4) {
|
149
|
+
newOptions.maxWidth = options.maxHeight;
|
150
|
+
newOptions.maxHeight = options.maxWidth;
|
151
|
+
newOptions.minWidth = options.minHeight;
|
152
|
+
newOptions.minHeight = options.minWidth;
|
153
|
+
newOptions.sourceWidth = options.sourceHeight;
|
154
|
+
newOptions.sourceHeight = options.sourceWidth;
|
155
|
+
}
|
156
|
+
return newOptions;
|
157
|
+
};
|
158
|
+
|
159
|
+
}));
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* JavaScript Load Image 1.
|
2
|
+
* JavaScript Load Image 1.9.0
|
3
3
|
* https://github.com/blueimp/JavaScript-Load-Image
|
4
4
|
*
|
5
5
|
* Copyright 2011, Sebastian Tschan
|
@@ -72,53 +72,17 @@
|
|
72
72
|
return Object.prototype.toString.call(obj) === '[object ' + type + ']';
|
73
73
|
};
|
74
74
|
|
75
|
-
// Transform image
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
// horizontal flip
|
87
|
-
ctx.translate(width, 0);
|
88
|
-
ctx.scale(-1, 1);
|
89
|
-
break;
|
90
|
-
case 3:
|
91
|
-
// 180 rotate left
|
92
|
-
ctx.translate(width, height);
|
93
|
-
ctx.rotate(Math.PI);
|
94
|
-
break;
|
95
|
-
case 4:
|
96
|
-
// vertical flip
|
97
|
-
ctx.translate(0, height);
|
98
|
-
ctx.scale(1, -1);
|
99
|
-
break;
|
100
|
-
case 5:
|
101
|
-
// vertical flip + 90 rotate right
|
102
|
-
ctx.rotate(0.5 * Math.PI);
|
103
|
-
ctx.scale(1, -1);
|
104
|
-
break;
|
105
|
-
case 6:
|
106
|
-
// 90 rotate right
|
107
|
-
ctx.rotate(0.5 * Math.PI);
|
108
|
-
ctx.translate(0, -height);
|
109
|
-
break;
|
110
|
-
case 7:
|
111
|
-
// horizontal flip + 90 rotate right
|
112
|
-
ctx.rotate(0.5 * Math.PI);
|
113
|
-
ctx.translate(width, -height);
|
114
|
-
ctx.scale(-1, 1);
|
115
|
-
break;
|
116
|
-
case 8:
|
117
|
-
// 90 rotate left
|
118
|
-
ctx.rotate(-0.5 * Math.PI);
|
119
|
-
ctx.translate(-width, 0);
|
120
|
-
break;
|
121
|
-
}
|
75
|
+
// Transform image coordinates, allows to override e.g.
|
76
|
+
// the canvas orientation based on the orientation option,
|
77
|
+
// gets canvas, options passed as arguments:
|
78
|
+
loadImage.transformCoordinates = function () {
|
79
|
+
return;
|
80
|
+
};
|
81
|
+
|
82
|
+
// Returns transformed options, allows to override e.g.
|
83
|
+
// coordinate and dimension options based on the orientation:
|
84
|
+
loadImage.getTransformedOptions = function (options) {
|
85
|
+
return options;
|
122
86
|
};
|
123
87
|
|
124
88
|
// Canvas render method, allows to override the
|
@@ -149,31 +113,35 @@
|
|
149
113
|
return canvas;
|
150
114
|
};
|
151
115
|
|
152
|
-
//
|
116
|
+
// This method is used to determine if the target image
|
117
|
+
// should be a canvas element:
|
118
|
+
loadImage.hasCanvasOption = function (options) {
|
119
|
+
return options.canvas || options.crop;
|
120
|
+
};
|
121
|
+
|
122
|
+
// Scales and/or crops the given image (img or canvas HTML element)
|
153
123
|
// using the given options.
|
154
124
|
// Returns a canvas object if the browser supports canvas
|
155
|
-
// and the
|
156
|
-
// is passed as image, else the scaled image:
|
125
|
+
// and the hasCanvasOption method returns true or a canvas
|
126
|
+
// object is passed as image, else the scaled image:
|
157
127
|
loadImage.scale = function (img, options) {
|
158
128
|
options = options || {};
|
159
129
|
var canvas = document.createElement('canvas'),
|
160
130
|
useCanvas = img.getContext ||
|
161
|
-
((options
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
sourceHeight = height,
|
167
|
-
sourceX = 0,
|
168
|
-
sourceY = 0,
|
169
|
-
destX = 0,
|
170
|
-
destY = 0,
|
131
|
+
(loadImage.hasCanvasOption(options) && canvas.getContext),
|
132
|
+
width = img.naturalWidth || img.width,
|
133
|
+
height = img.naturalHeight || img.height,
|
134
|
+
destWidth = width,
|
135
|
+
destHeight = height,
|
171
136
|
maxWidth,
|
172
137
|
maxHeight,
|
173
138
|
minWidth,
|
174
139
|
minHeight,
|
175
|
-
|
176
|
-
|
140
|
+
sourceWidth,
|
141
|
+
sourceHeight,
|
142
|
+
sourceX,
|
143
|
+
sourceY,
|
144
|
+
tmp,
|
177
145
|
scaleUp = function () {
|
178
146
|
var scale = Math.max(
|
179
147
|
(minWidth || destWidth) / destWidth,
|
@@ -194,34 +162,53 @@
|
|
194
162
|
destHeight = Math.ceil(destHeight * scale);
|
195
163
|
}
|
196
164
|
};
|
197
|
-
if (useCanvas
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
165
|
+
if (useCanvas) {
|
166
|
+
options = loadImage.getTransformedOptions(options);
|
167
|
+
sourceX = options.left || 0;
|
168
|
+
sourceY = options.top || 0;
|
169
|
+
if (options.sourceWidth) {
|
170
|
+
sourceWidth = options.sourceWidth;
|
171
|
+
if (options.right !== undefined && options.left === undefined) {
|
172
|
+
sourceX = width - sourceWidth - options.right;
|
173
|
+
}
|
174
|
+
} else {
|
175
|
+
sourceWidth = width - sourceX - (options.right || 0);
|
176
|
+
}
|
177
|
+
if (options.sourceHeight) {
|
178
|
+
sourceHeight = options.sourceHeight;
|
179
|
+
if (options.bottom !== undefined && options.top === undefined) {
|
180
|
+
sourceY = height - sourceHeight - options.bottom;
|
181
|
+
}
|
182
|
+
} else {
|
183
|
+
sourceHeight = height - sourceY - (options.bottom || 0);
|
184
|
+
}
|
185
|
+
destWidth = sourceWidth;
|
186
|
+
destHeight = sourceHeight;
|
207
187
|
}
|
188
|
+
maxWidth = options.maxWidth;
|
189
|
+
maxHeight = options.maxHeight;
|
190
|
+
minWidth = options.minWidth;
|
191
|
+
minHeight = options.minHeight;
|
208
192
|
if (useCanvas && maxWidth && maxHeight && options.crop) {
|
209
193
|
destWidth = maxWidth;
|
210
194
|
destHeight = maxHeight;
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
195
|
+
tmp = sourceWidth / sourceHeight - maxWidth / maxHeight;
|
196
|
+
if (tmp < 0) {
|
197
|
+
sourceHeight = maxHeight * sourceWidth / maxWidth;
|
198
|
+
if (options.top === undefined && options.bottom === undefined) {
|
199
|
+
sourceY = (height - sourceHeight) / 2;
|
200
|
+
}
|
201
|
+
} else if (tmp > 0) {
|
202
|
+
sourceWidth = maxWidth * sourceHeight / maxHeight;
|
203
|
+
if (options.left === undefined && options.right === undefined) {
|
204
|
+
sourceX = (width - sourceWidth) / 2;
|
205
|
+
}
|
217
206
|
}
|
218
207
|
} else {
|
219
208
|
if (options.contain || options.cover) {
|
220
209
|
minWidth = maxWidth = maxWidth || minWidth;
|
221
210
|
minHeight = maxHeight = maxHeight || minHeight;
|
222
211
|
}
|
223
|
-
destWidth = width;
|
224
|
-
destHeight = height;
|
225
212
|
if (options.cover) {
|
226
213
|
scaleDown();
|
227
214
|
scaleUp();
|
@@ -235,7 +222,7 @@
|
|
235
222
|
canvas.height = destHeight;
|
236
223
|
loadImage.transformCoordinates(
|
237
224
|
canvas,
|
238
|
-
options
|
225
|
+
options
|
239
226
|
);
|
240
227
|
return loadImage.renderImageToCanvas(
|
241
228
|
canvas,
|
@@ -244,8 +231,8 @@
|
|
244
231
|
sourceY,
|
245
232
|
sourceWidth,
|
246
233
|
sourceHeight,
|
247
|
-
|
248
|
-
|
234
|
+
0,
|
235
|
+
0,
|
249
236
|
destWidth,
|
250
237
|
destHeight
|
251
238
|
);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueimp-load-image-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Tschan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -42,12 +42,13 @@ extra_rdoc_files: []
|
|
42
42
|
files:
|
43
43
|
- lib/blueimp-load-image-rails.rb
|
44
44
|
- lib/blueimp-load-image-rails/version.rb
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
45
|
+
- app/assets/javascripts/blueimp-load-image.js
|
46
|
+
- app/assets/javascripts/load-image-exif-map.js
|
47
|
+
- app/assets/javascripts/load-image-exif.js
|
48
|
+
- app/assets/javascripts/load-image-ios.js
|
49
|
+
- app/assets/javascripts/load-image-meta.js
|
50
|
+
- app/assets/javascripts/load-image-orientation.js
|
51
|
+
- app/assets/javascripts/load-image.js
|
51
52
|
homepage: https://github.com/blueimp/JavaScript-Load-Image
|
52
53
|
licenses:
|
53
54
|
- MIT
|