|
1 | 1 | /*
|
2 |
| - * jQuery File Upload Image Preview & Resize Plugin 1.2.3 |
| 2 | + * jQuery File Upload Image Preview & Resize Plugin 1.3.0 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2013, Sebastian Tschan
|
|
64 | 64 | minWidth: '@',
|
65 | 65 | minHeight: '@',
|
66 | 66 | crop: '@',
|
| 67 | + orientation: '@', |
67 | 68 | disabled: '@disableImageResize'
|
68 | 69 | },
|
69 | 70 | {
|
|
109 | 110 | imageMaxWidth: 1920,
|
110 | 111 | // The maximum height of resized images:
|
111 | 112 | imageMaxHeight: 1080,
|
| 113 | + // Defines the image orientation (1-8) or takes the orientation |
| 114 | + // value from Exif data if set to true: |
| 115 | + imageOrientation: false, |
112 | 116 | // Define if resized images should be cropped or only scaled:
|
113 | 117 | imageCrop: false,
|
114 | 118 | // Disable the resize image functionality by default:
|
|
131 | 135 | processActions: {
|
132 | 136 |
|
133 | 137 | // Loads the image given via data.files and data.index
|
134 |
| - // as img element if the browser supports canvas. |
| 138 | + // as img element, if the browser supports the File API. |
135 | 139 | // Accepts the options fileTypes (regular expression)
|
136 | 140 | // and maxFileSize (integer) to limit the files to load:
|
137 | 141 | loadImage: function (data, options) {
|
|
162 | 166 |
|
163 | 167 | // Resizes the image given as data.canvas or data.img
|
164 | 168 | // and updates data.canvas or data.img with the resized image.
|
| 169 | + // Also stores the resized image as preview property. |
165 | 170 | // Accepts the options maxWidth, maxHeight, minWidth,
|
166 | 171 | // minHeight, canvas and crop:
|
167 | 172 | resizeImage: function (data, options) {
|
168 | 173 | if (options.disabled) {
|
169 | 174 | return data;
|
170 | 175 | }
|
| 176 | + options = $.extend({canvas: true}, options); |
171 | 177 | var that = this,
|
172 | 178 | dfd = $.Deferred(),
|
| 179 | + img = (options.canvas && data.canvas) || data.img, |
173 | 180 | resolve = function (newImg) {
|
174 |
| - data[newImg.getContext ? 'canvas' : 'img'] = newImg; |
| 181 | + if (newImg && (newImg.width !== img.width || |
| 182 | + newImg.height !== img.height)) { |
| 183 | + data[newImg.getContext ? 'canvas' : 'img'] = newImg; |
| 184 | + } |
| 185 | + data.preview = newImg; |
175 | 186 | dfd.resolveWith(that, [data]);
|
176 | 187 | },
|
177 |
| - thumbnail, |
178 |
| - img, |
179 |
| - newImg; |
180 |
| - options = $.extend({canvas: true}, options); |
| 188 | + thumbnail; |
181 | 189 | if (data.exif) {
|
182 | 190 | if (options.orientation === true) {
|
183 | 191 | options.orientation = data.exif.get('Orientation');
|
|
190 | 198 | }
|
191 | 199 | }
|
192 | 200 | }
|
193 |
| - img = (options.canvas && data.canvas) || data.img; |
194 | 201 | if (img) {
|
195 |
| - newImg = loadImage.scale(img, options); |
196 |
| - if (newImg.width !== img.width || |
197 |
| - newImg.height !== img.height) { |
198 |
| - resolve(newImg); |
199 |
| - return dfd.promise(); |
200 |
| - } |
| 202 | + resolve(loadImage.scale(img, options)); |
| 203 | + return dfd.promise(); |
201 | 204 | }
|
202 | 205 | return data;
|
203 | 206 | },
|
|
278 | 281 | // Sets the resized version of the image as a property of the
|
279 | 282 | // file object, must be called after "saveImage":
|
280 | 283 | setImage: function (data, options) {
|
281 |
| - var img = data.canvas || data.img; |
282 |
| - if (img && !options.disabled) { |
283 |
| - data.files[data.index][options.name || 'preview'] = img; |
| 284 | + if (data.preview && !options.disabled) { |
| 285 | + data.files[data.index][options.name || 'preview'] = data.preview; |
284 | 286 | }
|
285 | 287 | return data;
|
286 | 288 | }
|
|
0 commit comments