mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-08-29 02:32:54 +08:00
Apply EXIF orientation when converting images with ImageMagick (#577)
This commit is contained in:
@@ -468,6 +468,10 @@ export function convert(
|
||||
outputArgs.push("-background", "white", "-alpha", "remove");
|
||||
}
|
||||
|
||||
// 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
|
||||
outputArgs.push("-auto-orient");
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile(
|
||||
"magick",
|
||||
|
||||
@@ -163,3 +163,19 @@ test("convert respects emf as input filetype", async () => {
|
||||
);
|
||||
expect(loggedMessage).toBe("stdout: Fake stdout");
|
||||
});
|
||||
|
||||
test("convert applies EXIF auto-orient", async () => {
|
||||
const mockExecFile: ExecFileFn = (
|
||||
_cmd: string,
|
||||
_args: string[],
|
||||
callback: (err: ExecFileException | null, stdout: string, stderr: string) => void,
|
||||
) => {
|
||||
calls.push(_args);
|
||||
callback(null, "", "");
|
||||
};
|
||||
|
||||
const result = await convert("input.jpg", "jpg", "png", "output.png", undefined, mockExecFile);
|
||||
|
||||
expect(result).toBe("Done");
|
||||
expect(calls[0]).toEqual(expect.arrayContaining(["input.jpg", "-auto-orient", "output.png"]));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user