Use the updated im 7

This commit is contained in:
Manav Rathi 2025-01-21 16:21:44 +05:30
parent 75509ff339
commit d836e190e3
No known key found for this signature in database
2 changed files with 20 additions and 14 deletions

View File

@ -103,7 +103,7 @@ Some extra ones specific to the code here are:
### Format conversion ### Format conversion
The main tool we use is for arbitrary conversions is ffmpeg. To bundle a For video conversions and metadata extraction, we use ffmpeg. To bundle a
(platform specific) static binary of ffmpeg with our app, we use (platform specific) static binary of ffmpeg with our app, we use
[ffmpeg-static](https://github.com/eugeneware/ffmpeg-static). [ffmpeg-static](https://github.com/eugeneware/ffmpeg-static).
@ -111,11 +111,11 @@ The main tool we use is for arbitrary conversions is ffmpeg. To bundle a
> ffmpeg binary and using the wasm one (that our renderer process already has). > ffmpeg binary and using the wasm one (that our renderer process already has).
> Which is why we bundle it to speed up operations on the desktop app. > Which is why we bundle it to speed up operations on the desktop app.
On Linux and Windows, we use ImageMagick for thumbnail generation. A static On Linux and Windows, we use ImageMagick for thumbnail generation and JPEG
OS/architecture specific binary of this is bundled in our extra resources conversion of unpreviewable images. A static OS/architecture specific binary of
(`build`) folder by `scripts/magick.sh`. this is bundled in our extra resources (`build`) folder by `scripts/magick.sh`.
On macOS, we use the `sips` CLI tool for conversion, but that is already On macOS, we use the `sips` CLI tool for these tasks, but that is already
available on the host machine, and is not bundled with our app. available on the host machine, and is not bundled with our app.
### ML ### ML

View File

@ -44,25 +44,29 @@ const convertToJPEGCommand = (
]; ];
case "linux": case "linux":
// The bundled binary is an ELF x86-64 executable. case "win32":
if (process.arch != "x64") // The bundled binary is for x86 and arm64.
if (process.arch != "x64" && process.arch != "arm64")
throw new Error(CustomErrorMessage.NotAvailable); throw new Error(CustomErrorMessage.NotAvailable);
return [ return [
imageMagickPath(), imageMagickPath(),
"convert",
inputFilePath, inputFilePath,
"-quality", "-quality",
"100%", "100%",
outputFilePath, outputFilePath,
]; ];
default: // "win32" default:
throw new Error(CustomErrorMessage.NotAvailable); throw new Error(CustomErrorMessage.NotAvailable);
} }
}; };
/** Path to the Linux image-magick executable bundled with our app */ /**
* Path to the magick executable bundled with our app on Linux and Windows.
*/
const imageMagickPath = () => const imageMagickPath = () =>
path.join(isDev ? "build" : process.resourcesPath, "image-magick"); path.join(isDev ? "build" : process.resourcesPath, "magick");
export const generateImageThumbnail = async ( export const generateImageThumbnail = async (
dataOrPathOrZipItem: Uint8Array | string | ZipItem, dataOrPathOrZipItem: Uint8Array | string | ZipItem,
@ -133,14 +137,16 @@ const generateImageThumbnailCommand = (
]; ];
case "linux": case "linux":
// The bundled binary is an ELF x86-64 executable. case "win32":
if (process.arch != "x64") // The bundled binary is for x86 and arm64.
if (process.arch != "x64" && process.arch != "arm64")
throw new Error(CustomErrorMessage.NotAvailable); throw new Error(CustomErrorMessage.NotAvailable);
return [ return [
imageMagickPath(), imageMagickPath(),
"convert",
inputFilePath,
"-define", "-define",
`jpeg:size=${2 * maxDimension}x${2 * maxDimension}`, `jpeg:size=${2 * maxDimension}x${2 * maxDimension}`,
inputFilePath,
"-auto-orient", "-auto-orient",
"-thumbnail", "-thumbnail",
`${maxDimension}x${maxDimension}`, `${maxDimension}x${maxDimension}`,
@ -151,7 +157,7 @@ const generateImageThumbnailCommand = (
outputFilePath, outputFilePath,
]; ];
default: // "win32" default:
throw new Error(CustomErrorMessage.NotAvailable); throw new Error(CustomErrorMessage.NotAvailable);
} }
}; };