Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: extending smaller images when used thumbnails or backgrounds

Ilian Sapundshieva0f60762b48b
diff --git a/app/services/thumbsgenerator.ts b/app/services/thumbsgenerator.ts
index 31af371a8..641288aa5 100644
--- a/app/services/thumbsgenerator.ts
+++ b/app/services/thumbsgenerator.ts
@@ -373,18 +373,22 @@ export function generateImageThumbnail(
// default:
// // ctx.rotate(0);
// }
- // if (img.width > maxSize || img.height > maxSize) { // uncomment to do not extend smaller images
+ let maxSizeWidth = maxSize;
+ if (img.width < maxSize) {
+ maxSizeWidth = img.width;
+ }
+ let maxSizeHeight = maxSize;
+ if (img.height < maxSize) {
+ maxSizeHeight = img.height;
+ }
if (img.width >= img.height) {
- canvas.width = maxSize;
- canvas.height = (maxSize * img.height) / img.width;
+ canvas.width = maxSizeWidth;
+ canvas.height = (maxSizeWidth * img.height) / img.width;
} else {
- canvas.height = maxSize;
- canvas.width = (maxSize * img.width) / img.height;
+ canvas.height = maxSizeHeight;
+ canvas.width = (maxSizeHeight * img.width) / img.height;
}
- // } else {
- // canvas.width = img.width;
- // canvas.height = img.height;
- // }
+
const { width, height } = canvas;
const x = canvas.width / 2;
const y = canvas.height / 2;