






















@@ -75,4 +75,51 @@ describe("image ops Rastermill adapter", () => {
7575resizeToJpeg({ buffer: Buffer.from("input"), maxSide: 1, quality: 80 }),
7676).rejects.toBeInstanceOf(ImageProcessorUnavailableError);
7777});
78+79+it("returns oriented bytes when EXIF metadata probe is unavailable but encode succeeds", async () => {
80+const encoded = Buffer.from("oriented");
81+const encode = vi.fn(async () => ({ data: encoded }));
82+const probe = vi.fn(async () => null);
83+84+vi.doMock("rastermill", () => ({
85+RastermillUnavailableError: class RastermillUnavailableError extends Error {
86+causes = [];
87+},
88+createRastermill: vi.fn(() => ({ encode, probe })),
89+isRastermillUnavailableError: () => false,
90+readImageMetadataFromHeader: vi.fn(() => ({ width: 1, height: 1 })),
91+readImageProbeFromHeader: vi.fn(() => ({ width: 1, height: 1, format: "jpeg" })),
92+}));
93+94+const { normalizeExifOrientation } = await import("./image-ops.js");
95+96+await expect(normalizeExifOrientation(Buffer.from("input"))).resolves.toEqual(encoded);
97+expect(encode).toHaveBeenCalledWith(Buffer.from("input"), {
98+format: "jpeg",
99+autoOrient: true,
100+});
101+});
102+103+it("leaves EXIF normalization best-effort when Rastermill is unavailable", async () => {
104+class RastermillUnavailableError extends Error {
105+readonly causes = [new Error("missing backend")];
106+}
107+const source = Buffer.from("input");
108+const encode = vi.fn(async () => {
109+throw new RastermillUnavailableError("Image processor unavailable");
110+});
111+const probe = vi.fn(async () => ({ width: 1, height: 1, orientation: 6 }));
112+113+vi.doMock("rastermill", () => ({
114+ RastermillUnavailableError,
115+createRastermill: vi.fn(() => ({ encode, probe })),
116+isRastermillUnavailableError: (error: unknown) => error instanceof RastermillUnavailableError,
117+readImageMetadataFromHeader: vi.fn(() => ({ width: 1, height: 1 })),
118+readImageProbeFromHeader: vi.fn(() => ({ width: 1, height: 1, format: "jpeg" })),
119+}));
120+121+const { normalizeExifOrientation } = await import("./image-ops.js");
122+123+await expect(normalizeExifOrientation(source)).resolves.toBe(source);
124+});
78125});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。