[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");
// 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,
@ -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(
@ -138,14 +140,17 @@ 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,
"-auto-orient",
"-define",
`jpeg:size=${2 * maxDimension}x${2 * maxDimension}`,
inputFilePath,
"-auto-orient",
"-thumbnail",
`${maxDimension}x${maxDimension}>`,
`${maxDimension}x${maxDimension}`,
"-unsharp",
"0x.5",
"-quality",