When I call the Remove Background API, the result image gets rotated

A: An image can be rotated through a value set inside the EXIF metadata of the image.

Because the Remove Background API doesn’t carry over EXIF metadata into the result image, the rotation will then get lost in the process.

The best solution to this problem is to physically perform the rotation by rotating the image itself before making the API call.

Here’s an example of how to do it when using the JavaScript library sharp:

Copy

async function removeImageBackground (imageBuffer) {
    // Normalize the image orientation based on its EXIF Orientation tag
    // Then reset the EXIF Orientation tag to 1
    const normalizedImageBuffer = await sharp (imageBuffer)
        .rotate() // Automatically adjust rotation based on EXIF data
        .withMetadata({ orientation: 1 }) // Reset EXIF Orientation tag to 1
        .toBuffer(); // Convert back to buffer for further processing

    console. log ('Image orientation normalized to EXIF rotation value 1.');

    // Make the API call
}

This problem should not happen when using the Image Editing API.

Got same issue here ! Apply some postprocessing to compare with input image

1 Like