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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8133cf8c64435ad3168dd29b095059df333d32a3
4
- data.tar.gz: 5f1f05730295c1ffdd58a47ebe3693e2399f25a6
3
+ metadata.gz: fbb9643e780934f976c80f31783a97f58ea7e81a
4
+ data.tar.gz: 1465e3a4a2d1692d513325f1e3975127e19e021d
5
5
  SHA512:
6
- metadata.gz: b27c7863a034c4bd3de0b52279f0db569800586daf10db97cc5ff63102ce7f5215883650ac0db4c01b50251e6b2d065df4d68f0fc0bb6516f230bc217b56a25b
7
- data.tar.gz: 647256f48a2a63c9a90ad98d06bd7e6fb42eab3b2f8d8becaf54362788837f46a4852a314ff321eb4c1a850c420284e8c473f1a280e6f4bb1aa196bb51c534db
6
+ metadata.gz: 35b880d2320a6c96ed59c5a72719fb0797ad289a0b3c398879eb06654ee7c0b07c59b8cd9bd7999ec2be65ceac216b343a64b4f157fdb1864ce31d9ba4ede4a9
7
+ data.tar.gz: 98e7eff6674aff85875affcd77c9a1bba150d78dfff2aff5e165d4aaf14bd583c86b077ae85235e3b0258812500cabba4f000ddfd4e53f91d4ef5e943e6da1cd
@@ -1,5 +1,6 @@
1
1
  //= require load-image
2
2
  //= require load-image-ios
3
+ //= require load-image-orientation
3
4
  //= require load-image-meta
4
5
  //= require load-image-exif
5
6
  //= require load-image-exif-map
@@ -1,5 +1,5 @@
1
1
  /*
2
- * JavaScript Load Image iOS scaling fixes 1.0.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, correctedHeight) {
57
- var canvas = document.createElement('canvas'),
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 = correctedHeight;
69
+ canvas.height = naturalHeight;
66
70
  context.drawImage(img, 0, 0);
67
- data = context.getImageData(0, 0, 1, correctedHeight).data;
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 = correctedHeight;
71
- py = correctedHeight;
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 / correctedHeight) || 1;
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
- subSampled,
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
- subSampled = loadImage.detectSubsampling(img);
111
- if (subSampled) {
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, sourceHeight);
116
- if (subSampled && vertSquashRatio !== 1) {
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
@@ -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.8.0
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 orientation based on the given EXIF orientation data:
76
- loadImage.transformCoordinates = function (canvas, orientation) {
77
- var ctx = canvas.getContext('2d'),
78
- width = canvas.width,
79
- height = canvas.height;
80
- if (orientation > 4) {
81
- canvas.width = height;
82
- canvas.height = width;
83
- }
84
- switch (orientation) {
85
- case 2:
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
- // Scales the given image (img or canvas HTML element)
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 canvas or crop option is true or a canvas object
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.canvas || options.crop || options.orientation) &&
162
- canvas.getContext),
163
- width = img.width,
164
- height = img.height,
165
- sourceWidth = width,
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
- destWidth,
176
- destHeight,
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 && options.orientation > 4) {
198
- maxWidth = options.maxHeight;
199
- maxHeight = options.maxWidth;
200
- minWidth = options.minHeight;
201
- minHeight = options.minWidth;
202
- } else {
203
- maxWidth = options.maxWidth;
204
- maxHeight = options.maxHeight;
205
- minWidth = options.minWidth;
206
- minHeight = options.minHeight;
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
- if (width / height < maxWidth / maxHeight) {
212
- sourceHeight = maxHeight * width / maxWidth;
213
- sourceY = (height - sourceHeight) / 2;
214
- } else {
215
- sourceWidth = maxWidth * height / maxHeight;
216
- sourceX = (width - sourceWidth) / 2;
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.orientation
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
- destX,
248
- destY,
234
+ 0,
235
+ 0,
249
236
  destWidth,
250
237
  destHeight
251
238
  );
@@ -5,7 +5,7 @@ module Blueimp
5
5
  class Version
6
6
  class << self
7
7
  def to_s
8
- "1.8.0"
8
+ "1.9.1"
9
9
  end
10
10
  end
11
11
  end
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.8.0
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-11 00:00:00.000000000 Z
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
- - vendor/assets/javascripts/blueimp-load-image.js
46
- - vendor/assets/javascripts/load-image-exif-map.js
47
- - vendor/assets/javascripts/load-image-exif.js
48
- - vendor/assets/javascripts/load-image-ios.js
49
- - vendor/assets/javascripts/load-image-meta.js
50
- - vendor/assets/javascripts/load-image.js
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