[desktop] Imagemagick related tweaks (#1707)

Related: https://github.com/ente-io/ImageMagick
This commit is contained in:
Manav Rathi 2024-05-13 13:05:45 +05:30 committed by GitHub
commit acc3f7b30f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -79,7 +79,7 @@ export const generateImageThumbnail = async (
const outputFilePath = await makeTempFilePath("jpeg"); 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 quality = 70;
let command = generateImageThumbnailCommand( let command = generateImageThumbnailCommand(
inputFilePath, inputFilePath,
@ -94,6 +94,8 @@ export const generateImageThumbnail = async (
let thumbnail: Uint8Array; let thumbnail: Uint8Array;
do { do {
await execAsync(command); 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)); thumbnail = new Uint8Array(await fs.readFile(outputFilePath));
quality -= 10; quality -= 10;
command = generateImageThumbnailCommand( command = generateImageThumbnailCommand(
@ -138,14 +140,17 @@ const generateImageThumbnailCommand = (
]; ];
case "linux": case "linux":
// The bundled binary is an ELF x86-64 executable.
if (process.arch != "x64")
throw new Error(CustomErrorMessage.NotAvailable);
return [ return [
imageMagickPath(), imageMagickPath(),
inputFilePath,
"-auto-orient",
"-define", "-define",
`jpeg:size=${2 * maxDimension}x${2 * maxDimension}`, `jpeg:size=${2 * maxDimension}x${2 * maxDimension}`,
inputFilePath,
"-auto-orient",
"-thumbnail", "-thumbnail",
`${maxDimension}x${maxDimension}>`, `${maxDimension}x${maxDimension}`,
"-unsharp", "-unsharp",
"0x.5", "0x.5",
"-quality", "-quality",