Skip to content

Commit 5faa5f6

Browse files
committed
fix: uncaught exceptions, still need to reject promise
1 parent b14e2df commit 5faa5f6

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

js/load-image-orientation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ Exif orientation values to correctly display the letter F:
8787
$.orientation = img.width === 2 && img.height === 3
8888
if ($.orientation) {
8989
var canvas = $.createCanvas(1, 1, true)
90-
var ctx = canvas.getContext('2d')
91-
ctx.drawImage(img, 1, 1, 1, 1, 0, 0, 1, 1)
90+
try {
91+
var ctx = canvas.getContext('2d')
92+
ctx.drawImage(img, 1, 1, 1, 1, 0, 0, 1, 1)
93+
} catch (error) {
94+
// @todo: reject promise
95+
}
9296
// Check if the source image coordinates (sX, sY, sWidth, sHeight) are
9397
// correctly applied to the auto-orientated image, which should result
9498
// in a white opaque pixel (e.g. in Safari).

js/load-image-scale.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,29 @@
9696
destHeight,
9797
options
9898
) {
99-
var ctx = canvas.getContext('2d')
100-
if (options.imageSmoothingEnabled === false) {
101-
ctx.msImageSmoothingEnabled = false
102-
ctx.imageSmoothingEnabled = false
103-
} else if (options.imageSmoothingQuality) {
104-
ctx.imageSmoothingQuality = options.imageSmoothingQuality
99+
try {
100+
var ctx = canvas.getContext('2d')
101+
if (options.imageSmoothingEnabled === false) {
102+
ctx.msImageSmoothingEnabled = false
103+
ctx.imageSmoothingEnabled = false
104+
} else if (options.imageSmoothingQuality) {
105+
ctx.imageSmoothingQuality = options.imageSmoothingQuality
106+
}
107+
ctx.drawImage(
108+
img,
109+
sourceX,
110+
sourceY,
111+
sourceWidth,
112+
sourceHeight,
113+
0,
114+
0,
115+
destWidth,
116+
destHeight
117+
)
118+
return ctx
119+
} catch (error) {
120+
// @todo: reject promise upon error
105121
}
106-
ctx.drawImage(
107-
img,
108-
sourceX,
109-
sourceY,
110-
sourceWidth,
111-
sourceHeight,
112-
0,
113-
0,
114-
destWidth,
115-
destHeight
116-
)
117-
return ctx
118122
}
119123

120124
// Determines if the target image should be a canvas element:

0 commit comments

Comments
 (0)