Skip to content

Commit 8776ebe

Browse files
committed
Limit pixel ratio handling to scaling library.
1 parent 996dbb1 commit 8776ebe

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

js/load-image-orientation.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,9 @@ Exif orientation values to correctly display the letter F:
235235
var ctx = canvas.getContext('2d')
236236
var width = canvas.width
237237
var height = canvas.height
238-
var styleWidth = canvas.style.width
239-
var styleHeight = canvas.style.height
240238
if (orientation > 4) {
241239
canvas.width = height
242240
canvas.height = width
243-
canvas.style.width = styleHeight
244-
canvas.style.height = styleWidth
245241
}
246242
switch (orientation) {
247243
case 2:

js/load-image-scale.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,14 @@
220220
}
221221
if (useCanvas) {
222222
pixelRatio = options.pixelRatio
223-
if (pixelRatio > 1) {
224-
if (parseInt(img.style.width, 10) === width / pixelRatio) {
225-
// Source image is already scaled according to device pixel ratio
226-
canvas.style.width = destWidth / pixelRatio + 'px'
227-
canvas.style.height = destHeight / pixelRatio + 'px'
228-
} else {
229-
canvas.style.width = destWidth + 'px'
230-
canvas.style.height = destHeight + 'px'
231-
destWidth *= pixelRatio
232-
destHeight *= pixelRatio
233-
canvas.getContext('2d').scale(pixelRatio, pixelRatio)
234-
}
223+
if (
224+
pixelRatio > 1 &&
225+
// Check if image has not yet device pixel ratio applied:
226+
parseInt(img.style.width, 10) !== width / pixelRatio
227+
) {
228+
destWidth *= pixelRatio
229+
destHeight *= pixelRatio
230+
canvas.getContext('2d').scale(pixelRatio, pixelRatio)
235231
}
236232
downsamplingRatio = options.downsamplingRatio
237233
if (
@@ -278,6 +274,10 @@
278274
canvas.width = destWidth
279275
canvas.height = destHeight
280276
loadImage.transformCoordinates(canvas, options, data)
277+
if (pixelRatio > 1) {
278+
canvas.style.width = canvas.width / pixelRatio + 'px'
279+
canvas.style.height = canvas.height / pixelRatio + 'px'
280+
}
281281
return loadImage.renderImageToCanvas(
282282
canvas,
283283
img,

0 commit comments

Comments
 (0)