Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Murray Roke 503 posts 966 karma points c-trib
    Oct 17, 2023 @ 02:44
    Murray Roke
    0

    ImageSharp processing images end up rotated sideways

    Hi All, I'm facing an issue where imagesharp resizes an image and it sometimes ends up sideways. If I set format=webp then it's sideways (or upside down. if format=jpg it's correct

    I believe it's something to do with EXIF orientation metadata. This document seems relevant: https://docs.sixlabors.com/api/ImageSharp/SixLabors.ImageSharp.Processing.AutoOrientExtensions.html

    If you want some example images download a the zip file from this page: https://www.galloway.me.uk/2012/01/uiimageorientation-exif-orientation-sample-images/

  • Murray Roke 503 posts 966 karma points c-trib
    Oct 17, 2023 @ 02:45
    Murray Roke
    101

    And the answer is:

    Add autoorient=true to the query string, or automatically to all image processor tasks like so:

    public class ConfigureImageSharpMiddlewareOptionsComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
            => builder.Services.Configure<ImageSharpMiddlewareOptions>(options =>
            {
                // Capture existing task to not overwrite it
                var onParseCommandsAsync = options.OnParseCommandsAsync;
                options.OnParseCommandsAsync = async context =>
                {
                    // Custom logic before
                    context.Commands.Add("autoorient","true");
    
                    await onParseCommandsAsync(context);
    
                    // Custom logic after
                };
            });
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft