Skip to content

Conversation

@CleanCodeDeveloper
Copy link
Contributor

@CleanCodeDeveloper CleanCodeDeveloper commented Jan 8, 2022

Summary of the Pull Request

What is this about:
Fix auto width/height feature that it works again as described:

Auto width/height
You can leave the height or width empty. This will honor the specified dimension and "lock" the other dimension to a value proportional to the original image aspect ratio.
Image Resizer, Microsoft Docs

Using a blank in the width/height field causes the image resizer to crash as described in #15306.

My guess is that this was a regression from the Newtonsoft.Json to System.Json.Text migration for JSON Settings serialization (if that ever happened, just guessing). Unfortunately, System.Json.Text handles cases like NaN differently than Newtonsoft.Json. Support for native support for "Named Floating Point Literals" where added with version 5 of System.Text.Json. See Microsoft Docs for further details.

I first thought that we need to wait for the .NET 6 migration to fix this due to the need for v5 System.Text.Json. Turns out that we already using System.Text.Json v5.0.2 in ImageResizer so here’s the fix.

What is included in the PR:
Added JsonSerializerOptions in the settings serialization class of image resizer.

How does someone test / validate:

Quality Checklist

Contributor License Agreement (CLA)

A CLA must be signed. If not, go over here and sign the CLA.

@CleanCodeDeveloper CleanCodeDeveloper marked this pull request as ready for review January 9, 2022 14:45
Copy link
Contributor

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution!

Copy link
Contributor

@SeraphimaZykova SeraphimaZykova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, works as expected. Nice work!

@jaimecbernardo
Copy link
Contributor

Thank you for the contribution!

@jaimecbernardo jaimecbernardo merged commit ac4f725 into microsoft:main Jan 21, 2022
@CleanCodeDeveloper CleanCodeDeveloper deleted the fix/image-resizer-#15306-Support-blanks-for-width-and-height- branch January 21, 2022 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants