Skip to content

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

fix: generating thumbs from jpgs files in chrome 81 and higher

Ilian Sapundshieve43a1f6d9f62
diff --git a/app/services/thumbsgenerator.ts b/app/services/thumbsgenerator.ts
index 7739df971..6390357d7 100644
--- a/app/services/thumbsgenerator.ts
+++ b/app/services/thumbsgenerator.ts
@@ -300,60 +300,62 @@ function generateImageThumbnail(fileURL): Promise<string> {
img.crossOrigin = 'anonymous';
img.onload = () => {
- EXIF.getData(img as any, function() {
- // TODO Use EXIF only for jpegs
- const orientation = EXIF.getTag(this, 'Orientation');
- /*
- 1 - 0 degrees – the correct orientation, no adjustment is required.
- 2 - 0 degrees, mirrored – image has been flipped back-to-front.
- 3 - 180 degrees – image is upside down.
- 4 - 180 degrees, mirrored – image is upside down and flipped back-to-front.
- 5 - 90 degrees – image is on its side.
- 6 - 90 degrees, mirrored – image is on its side and flipped back-to-front.
- 7 - 270 degrees – image is on its far side.
- 8 - 270 degrees, mirrored – image is on its far side and flipped back-to-front.
- */
- let angleInRadians;
- switch (orientation) {
- case 8:
- angleInRadians = 270 * (Math.PI / 180);
- break;
- case 3:
- angleInRadians = 180 * (Math.PI / 180);
- break;
- case 6:
- angleInRadians = 90 * (Math.PI / 180);
- break;
- case 1:
- // ctx.rotate(0);
- break;
- default:
- // ctx.rotate(0);
- }
- if (img.width >= img.height) {
- canvas.width = maxSize;
- canvas.height = (maxSize * img.height) / img.width;
- } else {
- canvas.height = maxSize;
- canvas.width = (maxSize * img.width) / img.height;
- }
- const width = canvas.width;
- const height = canvas.height;
- const x = canvas.width / 2;
- const y = canvas.height / 2;
+ // EXIF extraction not need because the image are rotated
+ // automatically in Chrome version 81 and higher
+ // EXIF.getData(img as any, function() {
+ // // TODO Use EXIF only for jpegs
+ // const orientation = EXIF.getTag(this, 'Orientation');
+ // /*
+ // 1 - 0 degrees – the correct orientation, no adjustment is required.
+ // 2 - 0 degrees, mirrored – image has been flipped back-to-front.
+ // 3 - 180 degrees – image is upside down.
+ // 4 - 180 degrees, mirrored – image is upside down and flipped back-to-front.
+ // 5 - 90 degrees – image is on its side.
+ // 6 - 90 degrees, mirrored – image is on its side and flipped back-to-front.
+ // 7 - 270 degrees – image is on its far side.
+ // 8 - 270 degrees, mirrored – image is on its far side and flipped back-to-front.
+ // */
+ // let angleInRadians;
+ // switch (orientation) {
+ // case 8:
+ // angleInRadians = 270 * (Math.PI / 180);
+ // break;
+ // case 3:
+ // angleInRadians = 180 * (Math.PI / 180);
+ // break;
+ // case 6:
+ // angleInRadians = 90 * (Math.PI / 180);
+ // break;
+ // case 1:
+ // // ctx.rotate(0);
+ // break;
+ // default:
+ // // ctx.rotate(0);
+ // }
+ if (img.width >= img.height) {
+ canvas.width = maxSize;
+ canvas.height = (maxSize * img.height) / img.width;
+ } else {
+ canvas.height = maxSize;
+ canvas.width = (maxSize * img.width) / img.height;
+ }
+ const { width } = canvas;
+ const { height } = canvas;
+ const x = canvas.width / 2;
+ const y = canvas.height / 2;
- ctx.translate(x, y);
- ctx.rotate(angleInRadians);
- ctx.fillStyle = bgColor;
- ctx.fillRect(-width / 2, -height / 2, width, height);
- ctx.drawImage(img, -width / 2, -height / 2, width, height);
- ctx.rotate(-angleInRadians);
- ctx.translate(-x, -y);
- const dataurl = canvas.toDataURL(AppConfig.thumbType);
- resolve(dataurl);
- img = null;
- canvas = null;
- });
+ ctx.translate(x, y);
+ // ctx.rotate(angleInRadians);
+ ctx.fillStyle = bgColor;
+ ctx.fillRect(-width / 2, -height / 2, width, height);
+ ctx.drawImage(img, -width / 2, -height / 2, width, height);
+ // ctx.rotate(-angleInRadians);
+ ctx.translate(-x, -y);
+ const dataurl = canvas.toDataURL(AppConfig.thumbType);
+ resolve(dataurl);
+ img = null;
+ canvas = null;
+ // });
};
img.src = fileURL;
img.onerror = errorHandler;