mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-09-13 02:14:32 +02:00
This commit is contained in:
@@ -317,8 +317,10 @@ export function convert(
|
||||
options?: unknown,
|
||||
execFile: ExecFileFn = execFileOriginal, // to make it mockable
|
||||
): Promise<string> {
|
||||
// Apply EXIF orientation so photos (e.g. from phones) don't end up sideways
|
||||
// when converted to formats where the orientation tag is lost or ignored
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile("gm", ["convert", filePath, targetPath], (error, stdout, stderr) => {
|
||||
execFile("gm", ["convert", filePath, "-auto-orient", targetPath], (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(`error: ${error}`);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,32 @@
|
||||
import { test } from "bun:test";
|
||||
import { beforeEach, expect, test } from "bun:test";
|
||||
import type { ExecFileException } from "node:child_process";
|
||||
import { convert } from "../../src/converters/graphicsmagick";
|
||||
import { ExecFileFn } from "../../src/converters/types";
|
||||
import { runCommonTests } from "./helpers/commonTests";
|
||||
|
||||
let calls: string[][] = [];
|
||||
|
||||
beforeEach(() => {
|
||||
calls = [];
|
||||
});
|
||||
|
||||
runCommonTests(convert);
|
||||
|
||||
test.skip("dummy - required to trigger test detection", () => {});
|
||||
test("convert applies EXIF auto-orient", async () => {
|
||||
let command = "";
|
||||
const mockExecFile: ExecFileFn = (
|
||||
cmd: string,
|
||||
args: string[],
|
||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||
) => {
|
||||
command = cmd;
|
||||
calls.push(args);
|
||||
callback(null, "", "");
|
||||
};
|
||||
|
||||
const result = await convert("input.jpg", "jpg", "pdf", "output.pdf", undefined, mockExecFile);
|
||||
|
||||
expect(result).toBe("Done");
|
||||
expect(command).toBe("gm");
|
||||
expect(calls[0]).toEqual(["convert", "input.jpg", "-auto-orient", "output.pdf"]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user