diff --git a/source/image-handler/image-handler.ts b/source/image-handler/image-handler.ts index 6dc7899b7..05b9316fd 100644 --- a/source/image-handler/image-handler.ts +++ b/source/image-handler/image-handler.ts @@ -192,7 +192,7 @@ export class ImageHandler { } case "rotate": { // Handle rotate specifically to support autoOrient when undefined - if (edits.rotate === undefined) { + if (edits.rotate === undefined || edits.rotate === null || edits.rotate === 'autoOrient') { // When rotate is undefined (filters:rotate() without parameters), call autoOrient() // This aligns with Sharp's behavior where rotate() without parameters auto-orients based on EXIF originalImage.autoOrient(); diff --git a/source/image-handler/test/image-handler/rotate.spec.ts b/source/image-handler/test/image-handler/rotate.spec.ts index fff812a4a..c5abf7bad 100644 --- a/source/image-handler/test/image-handler/rotate.spec.ts +++ b/source/image-handler/test/image-handler/rotate.spec.ts @@ -103,4 +103,54 @@ describe("rotate", () => { // Clean up autoOrientSpy.mockRestore(); }); + + it("Should call autoOrient when rotate is null (filters:rotate() without parameters)", async () => { + // Arrange + const originalImage = fs.readFileSync("./test/image/1x1.jpg"); + const request: ImageRequestInfo = { + requestType: RequestTypes.DEFAULT, + bucket: "sample-bucket", + key: "test.jpg", + edits: { rotate: null }, + originalImage, + }; + + // Create a spy on Sharp's autoOrient method + const autoOrientSpy = jest.spyOn(sharp.prototype, "autoOrient"); + + // Act + const imageHandler = new ImageHandler(s3Client, rekognitionClient); + await imageHandler.process(request); + + // Assert + expect(autoOrientSpy).toHaveBeenCalled(); + + // Clean up + autoOrientSpy.mockRestore(); + }); + + it("Should call autoOrient when rotate is 'autoOrient' (filters:rotate() without parameters)", async () => { + // Arrange + const originalImage = fs.readFileSync("./test/image/1x1.jpg"); + const request: ImageRequestInfo = { + requestType: RequestTypes.DEFAULT, + bucket: "sample-bucket", + key: "test.jpg", + edits: { rotate: "autoOrient" }, + originalImage, + }; + + // Create a spy on Sharp's autoOrient method + const autoOrientSpy = jest.spyOn(sharp.prototype, "autoOrient"); + + // Act + const imageHandler = new ImageHandler(s3Client, rekognitionClient); + await imageHandler.process(request); + + // Assert + expect(autoOrientSpy).toHaveBeenCalled(); + + // Clean up + autoOrientSpy.mockRestore(); + }); });