|
@@ -5,9 +5,18 @@ import { rmSync } from 'fs';
|
|
import { readFile, writeFile } from 'promise-fs';
|
|
import { readFile, writeFile } from 'promise-fs';
|
|
import { generateTempFilePath } from '../utils/temp';
|
|
import { generateTempFilePath } from '../utils/temp';
|
|
import { logErrorSentry } from './sentry';
|
|
import { logErrorSentry } from './sentry';
|
|
|
|
+import { isPlatform } from '../utils/main';
|
|
|
|
+import { isDev } from '../utils/common';
|
|
|
|
+import path from 'path';
|
|
|
|
|
|
const asyncExec = util.promisify(exec);
|
|
const asyncExec = util.promisify(exec);
|
|
|
|
|
|
|
|
+function getImageMagickStaticPath() {
|
|
|
|
+ return isDev
|
|
|
|
+ ? 'build/image-magick'
|
|
|
|
+ : path.join(process.resourcesPath, 'image-magick');
|
|
|
|
+}
|
|
|
|
+
|
|
export async function convertHEIC(
|
|
export async function convertHEIC(
|
|
heicFileData: Uint8Array
|
|
heicFileData: Uint8Array
|
|
): Promise<Uint8Array> {
|
|
): Promise<Uint8Array> {
|
|
@@ -19,9 +28,8 @@ export async function convertHEIC(
|
|
|
|
|
|
await writeFile(tempInputFilePath, heicFileData);
|
|
await writeFile(tempInputFilePath, heicFileData);
|
|
|
|
|
|
- await asyncExec(
|
|
|
|
- `sips -s format jpeg ${tempInputFilePath} --out ${tempOutputFilePath}`
|
|
|
|
- );
|
|
|
|
|
|
+ await runConvertCommand(tempInputFilePath, tempOutputFilePath);
|
|
|
|
+
|
|
const convertedFileData = new Uint8Array(
|
|
const convertedFileData = new Uint8Array(
|
|
await readFile(tempOutputFilePath)
|
|
await readFile(tempOutputFilePath)
|
|
);
|
|
);
|
|
@@ -42,3 +50,20 @@ export async function convertHEIC(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+async function runConvertCommand(
|
|
|
|
+ tempInputFilePath: string,
|
|
|
|
+ tempOutputFilePath: string
|
|
|
|
+) {
|
|
|
|
+ if (isPlatform('mac')) {
|
|
|
|
+ await asyncExec(
|
|
|
|
+ `sips -s format jpeg ${tempInputFilePath} --out ${tempOutputFilePath}`
|
|
|
|
+ );
|
|
|
|
+ } else if (isPlatform('linux')) {
|
|
|
|
+ await asyncExec(
|
|
|
|
+ `${getImageMagickStaticPath()} ${tempInputFilePath} -quality 100% ${tempOutputFilePath}`
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ Error(`${process.platform} native heic convert not supported yet`);
|
|
|
|
+ }
|
|
|
|
+}
|