Skip to content

Commit 79ff77c

Browse files
committed
Only create canvas element when needed.
1 parent 6ba07e3 commit 79ff77c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

js/load-image-scale.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@
119119
options = options || {}
120120
// eslint-disable-next-line no-param-reassign
121121
data = data || {}
122-
var canvas = document.createElement('canvas')
123122
var useCanvas =
124-
img.getContext || (loadImage.requiresCanvas(options) && canvas.getContext)
123+
img.getContext ||
124+
(loadImage.requiresCanvas(options) && !!window.HTMLCanvasElement)
125125
var width = img.naturalWidth || img.width
126126
var height = img.naturalHeight || img.height
127127
var destWidth = width
@@ -137,6 +137,7 @@
137137
var pixelRatio
138138
var downsamplingRatio
139139
var tmp
140+
var canvas
140141
/**
141142
* Scales up image dimensions
142143
*/
@@ -254,6 +255,7 @@
254255
options
255256
)
256257
}
258+
canvas = document.createElement('canvas')
257259
downsamplingRatio = options.downsamplingRatio
258260
if (
259261
downsamplingRatio > 0 &&

0 commit comments

Comments
 (0)