|
1 | 1 | /* |
2 | | - * JavaScript Load Image 1.1.5 |
| 2 | + * JavaScript Load Image 1.1.6 |
3 | 3 | * https://github.com/blueimp/JavaScript-Load-Image |
4 | 4 | * |
5 | 5 | * Copyright 2011, Sebastian Tschan |
|
49 | 49 | urlAPI = (window.createObjectURL && window) || |
50 | 50 | (window.URL && URL) || (window.webkitURL && webkitURL); |
51 | 51 |
|
52 | | - // Scales the given image (img HTML element) |
| 52 | + // Scales the given image (img or canvas HTML element) |
53 | 53 | // using the given options. |
54 | | - // Returns a canvas object if the canvas option is true |
55 | | - // and the browser supports canvas, else the scaled image: |
| 54 | + // Returns a canvas object if the browser supports canvas |
| 55 | + // and the canvas option is true or a canvas object is passed |
| 56 | + // as image, else the scaled image: |
56 | 57 | loadImage.scale = function (img, options) { |
57 | 58 | options = options || {}; |
58 | 59 | var canvas = document.createElement('canvas'), |
|
74 | 75 | width = parseInt(width * scale, 10); |
75 | 76 | height = parseInt(height * scale, 10); |
76 | 77 | } |
77 | | - if (!options.canvas || !canvas.getContext) { |
78 | | - img.width = width; |
79 | | - img.height = height; |
80 | | - return img; |
| 78 | + if (img.getContext || (options.canvas && canvas.getContext)) { |
| 79 | + canvas.width = width; |
| 80 | + canvas.height = height; |
| 81 | + canvas.getContext('2d') |
| 82 | + .drawImage(img, 0, 0, width, height); |
| 83 | + return canvas; |
81 | 84 | } |
82 | | - canvas.width = width; |
83 | | - canvas.height = height; |
84 | | - canvas.getContext('2d') |
85 | | - .drawImage(img, 0, 0, width, height); |
86 | | - return canvas; |
| 85 | + img.width = width; |
| 86 | + img.height = height; |
| 87 | + return img; |
87 | 88 | }; |
88 | 89 |
|
89 | 90 | loadImage.createObjectURL = function (file) { |
|
0 commit comments