Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/image-handler/image-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
50 changes: 50 additions & 0 deletions source/image-handler/test/image-handler/rotate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});