JonasKruckenberg / imagetools

Load and transform images using a toolbox :toolbox: of custom import directives!
MIT License
909 stars 56 forks source link

feat: add experimental image orientation fix #724

Open happycollision opened 3 months ago

happycollision commented 3 months ago

NOTE: This PR is incomplete, but the functionality is all there. It needs documentation and I need to better understand the tests in the Vite package to get those working the way I want. Everything else is ready. I don't have time for docs today, but I will get to them next week at the latest.

I will also rename commit summaries to be in keeping with the format you prefer, but won't do that right away.

Please feel free to start giving feedback about the runtime code and the idea itself.

Addresses #700 via an experimental setting.

🚨 I have not done everything on this list yet. I will do them, but I wanted to get some eyes on this draft first.

A new setting is added to both Vite config and as an option to pass into applyTransforms.

{
  experimental: {
    preserveInitialOrientation: boolean
  }
}

This opt-in feature will pre-rotate/flip/flop an image based on the EXIF orientation data so that downstream developers can think about their images without first considering whether or not the image appearance is affected by metadata or by actual pixel locations. Two images that look the same might have completely different results when applying flip, flop, or rotate. If you take removeMetadata into account, there are even more permutations to consider.

This new setting removes the need to consider all these things.

I have attempted to test initial behavior and ensure that, unless you opt-in, that behavior is exactly the same. So no, there shouldn't be any breaking changes.

changeset-bot[bot] commented 3 months ago

⚠️ No Changeset found

Latest commit: c9399520bf66607a1d52fb9a75d9f897e27a951b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

happycollision commented 3 months ago

I've discovered that the .withMetadata() method keeps all metadata while allowing you to write to some of that metadata at the same time. This means it is incompatible with the removeMetadata option. Looking into a different solution now...