From 9ca8ef9e74cad0594a49ea8a11e507725965a332 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 13 May 2024 11:21:27 +0530 Subject: [PATCH 1/4] The bundled binary is x86 only, bail out early on ARM Error: Error invoking remote method 'generateImageThumbnail': Error: Command failed: '/tmp/.mount_ente-1lYbIWw/resources/image-magick' '/home/m/Downloads/VM/IMG_4484.WEBP' -auto-orient -define 'jpeg:size=1440x1440' -thumbnail '720x720>' -unsharp '0x.5' -quality 70 '/tmp/ente/9aNsp1FdLe.jpeg' /bin/sh: 1: /tmp/.mount_ente-1lYbIWw/resources/image-magick: Exec format error The binary is from https://github.com/ente-io/ImageMagick/ --- desktop/src/main/services/image.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/desktop/src/main/services/image.ts b/desktop/src/main/services/image.ts index 957fe8120..db98f86dc 100644 --- a/desktop/src/main/services/image.ts +++ b/desktop/src/main/services/image.ts @@ -79,7 +79,7 @@ export const generateImageThumbnail = async ( const outputFilePath = await makeTempFilePath("jpeg"); - // Construct the command first, it may throw `NotAvailable` on win32. + // Construct the command first, it may throw `NotAvailable`. let quality = 70; let command = generateImageThumbnailCommand( inputFilePath, @@ -138,6 +138,9 @@ const generateImageThumbnailCommand = ( ]; case "linux": + // The bundled binary is an ELF x86-64 executable. + if (process.arch != "x64") + throw new Error(CustomErrorMessage.NotAvailable); return [ imageMagickPath(), inputFilePath, From 631b1772e42fd5c89240f14f79e0a7f9ec947b48 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 13 May 2024 11:31:34 +0530 Subject: [PATCH 2/4] Fix mangled parameter being passed to imagemagick Similar: https://github.com/ente-io/ente/pull/1175 --- desktop/src/main/services/image.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/src/main/services/image.ts b/desktop/src/main/services/image.ts index db98f86dc..64988f80f 100644 --- a/desktop/src/main/services/image.ts +++ b/desktop/src/main/services/image.ts @@ -148,7 +148,7 @@ const generateImageThumbnailCommand = ( "-define", `jpeg:size=${2 * maxDimension}x${2 * maxDimension}`, "-thumbnail", - `${maxDimension}x${maxDimension}>`, + `${maxDimension}x${maxDimension}`, "-unsharp", "0x.5", "-quality", From 957c2a64dff308ed1a426561f96838eec5eba95c Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 13 May 2024 11:33:25 +0530 Subject: [PATCH 3/4] Keep the order in the documentation examples https://imagemagick.org/Usage/thumbnails/ --- desktop/src/main/services/image.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/services/image.ts b/desktop/src/main/services/image.ts index 64988f80f..53c42acc8 100644 --- a/desktop/src/main/services/image.ts +++ b/desktop/src/main/services/image.ts @@ -143,10 +143,10 @@ const generateImageThumbnailCommand = ( throw new Error(CustomErrorMessage.NotAvailable); return [ imageMagickPath(), - inputFilePath, - "-auto-orient", "-define", `jpeg:size=${2 * maxDimension}x${2 * maxDimension}`, + inputFilePath, + "-auto-orient", "-thumbnail", `${maxDimension}x${maxDimension}`, "-unsharp", From b7292f26298caac2c84189aceb2ada1b186c21d3 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 13 May 2024 11:35:24 +0530 Subject: [PATCH 4/4] Add a log line for debugging --- desktop/src/main/services/image.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/desktop/src/main/services/image.ts b/desktop/src/main/services/image.ts index 53c42acc8..1e3c4b93b 100644 --- a/desktop/src/main/services/image.ts +++ b/desktop/src/main/services/image.ts @@ -94,6 +94,8 @@ export const generateImageThumbnail = async ( let thumbnail: Uint8Array; do { await execAsync(command); + // TODO(MR): imagemagick debugging. Remove me after verifying logs. + log.info(`Generated thumbnail using ${command.join(" ")}`); thumbnail = new Uint8Array(await fs.readFile(outputFilePath)); quality -= 10; command = generateImageThumbnailCommand(