fix(graphicsmagick): apply EXIF auto-orient so portrait images don't convert sideways (#590) (#637)

This commit is contained in:
JDubb
2026-09-09 13:34:44 -07:00
committed by GitHub
parent edb21f867b
commit 2ea8e00f1e
2 changed files with 30 additions and 3 deletions
+3 -1
View File
@@ -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}`);
}
+27 -2
View File
@@ -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"]);
});