ResizeWidthProportionally() turns image 90°

We use the ResizeWidthProportionally() function of Aspose.Imaging (.NET).
Some images are turned 90° after using above function.
We think this is related to the EXIF orientation metadata.
This is a common problem when working with images, especially those taken with smartphones.
Many mobile devices set an orientation flag in the EXIF metadata instead of physically rotating the image data. This can cause issues when the image is processed by software that doesn’t interpret this metadata correctly.
We have already tried to fix this with the RemoveMetadata() function but no luck.

Is it possible that Aspose.Imaging does not correctly interpret the orientating depending on the kind of deviced that was used to take the picture?
Does Aspose.Imaging contains a function to auto-rotate images based on their EXIF data so that we avoid the issues with unwanted rotation?

@wfbe

When using the ResizeWidthProportionally() function in Aspose.Imaging, it’s common to encounter issues with image orientation, particularly with images taken on mobile devices. This is often due to the EXIF orientation metadata, which indicates how the image should be displayed. If the software processing the image does not interpret this metadata correctly, it can result in unexpected rotations, such as turning the image 90 degrees.

To address this issue, Aspose.Imaging provides a method called AutoRotate(), which automatically adjusts the image orientation based on the EXIF data. This function reads the orientation flag from the EXIF metadata and rotates the image accordingly, ensuring that it is displayed correctly without manual intervention.

Here’s a simple example of how to use the AutoRotate() method in C#:

using Aspose.Imaging.FileFormats.Jpeg;
using System;

namespace Aspose.Imaging.Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load a JPEG image from file
            using (JpegImage image = (JpegImage)Image.Load("path/to/your/image.jpg"))
            {
                // Automatically rotate the image based on EXIF orientation
                image.AutoRotate();
                
                // Save the corrected image
                image.Save("path/to/your/corrected_image.jpg");
            }
        }
    }
}

This code snippet demonstrates how to load a JPEG image, apply the automatic rotation based on its EXIF data, and save the corrected image. By using this method, you can avoid issues with unwanted rotation when processing images.

If you have already tried removing metadata without success, ensure that you are using the AutoRotate() method after loading the image, as this is specifically designed to handle orientation issues related to EXIF data.

For further details, you can refer to the documentation on manipulating JPEG images with Aspose.Imaging, which provides additional insights into handling EXIF data and other image processing tasks.

Sources:
[1]: Manipulating JPEG Images - Aspose Documentation

1 Like

Hi, @wfbe
Tell me please, what version of Aspose.Imaging do you use?

Hi,
The answer of the Aspose bot solved the issue. I was impressed.
Can you put the bot answer back?
The solution was to use the AutoRotate() function.
Thanks!
Kind regards,
Wouter

1 Like

Happy to hear it!

Can you put the bot answer back?

Already done
But still, could you provide your version of Aspose.Imaging with us?

The version of Aspose.Imaging is 24.11.0

1 Like