Skip to content

Commit e027fbe

Browse files
author
Julien Droulez
committed
fix: default image sizes for pdf genration
1 parent ede315f commit e027fbe

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/composables/pdf-helpers/usePdfHelpers.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ export async function croppedImageData({ ratio, imgDataUrl, imageSizes }) {
1212
let left = 0
1313
let top = 0
1414
let scale = 1
15-
if ((ratio >= 1 && naturalRatio < 1) || (ratio < 1 && naturalRatio >= 1)) {
15+
if (ratio > naturalRatio) {
1616
// full width, crop top and bottom
17-
top = (-100 * (naturalHeight / 2 - naturalWidth / ratio / 2)) / naturalHeight
18-
scale = naturalHeight / naturalWidth / ratio
17+
const croppedHeight = naturalWidth / ratio
18+
scale = 1
19+
top = 100 * ((croppedHeight - naturalHeight) / 2 / naturalHeight)
1920
} else {
2021
// full height, crop left and right
21-
left = (-100 * (naturalWidth / 2 - (naturalHeight * ratio) / 2)) / naturalWidth
22-
scale = naturalWidth / (naturalHeight * ratio)
22+
const croppedWidth = naturalHeight * ratio
23+
scale = 1
24+
left = 100 * ((croppedWidth - naturalWidth) / 2 / naturalWidth)
2325
}
24-
2526
imageSizes = {
2627
left: left,
2728
top: top,

0 commit comments

Comments
 (0)