Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address out of order compatibility brands in Filetypebox of heif files #401

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

OliverSpeir
Copy link

Changes

  1. Add detectType function to /lib/types/heif.ts
  • This improve ability to accurately detect type for HEIF images where the compatibility brands are out of order
    • Currently heif.ts relies on the first brand in the FileTypeBox, but for example some .avif images do not have "avif" as the first type in their FileTypeBox
  1. Sets node version in package.json to 18.4 which shouldn't cause any problems as far as I am aware

Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

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

Thanks for this. Can we please add test images to assert these fixes, and to prevent any regressions in the future 🙏🏽

package.json Outdated Show resolved Hide resolved
lib/types/heif.ts Show resolved Hide resolved
Copy link

sonarcloud bot commented Feb 26, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@OliverSpeir
Copy link
Author

what I've done in order to achieve the tests is somewhat hacky, I'll admit. I didn't know how to generate the actual images that would correspond to these conditions, so I manually edited the type boxes of a .avif version of sample.png I created with sharp.

The way I discovered this condition is from an image in astro's tests. Here's the original image and I looked at how this images type box was structured and recreated it.

All of the test files I added have a very similiar structure, the only difference is to test each condition I changed the second brand. They all are structured like this:

Screenshot 2024-02-25 at 5 19 42 PM

@netroy Hopefully this makes sense and is viable in your opinion I am happy to rework / make any changes you'd like. Thank you

@OliverSpeir OliverSpeir changed the title Address out of order compatibility brands in Filetypebox of heif files and support older node version Address out of order compatibility brands in Filetypebox of heif files Mar 23, 2024
@netroy netroy changed the base branch from 2.0 to main April 7, 2024 12:06
@netroy
Copy link
Member

netroy commented Apr 8, 2024

I've been trying to find a way to create these images properly using a reliable tool. but no luck so far, as no tool lets us define the brands. The manually edited files look okay at a first glance, but the Image Properties section in my file browser shows a Failed to load image information only for the edited files. No such issues with light_walrus.avif though.
So, I'm guessing the manual editing of the brands isn't representative of actual images.
So, I'm conflicted about if I should delete those files, merge the PR, and just hope that this will continue to work as it should, or if I should keep looking for better tools for creating avif/heic/heif.

BTW, I've rebased this on the main branch, so that if this gets merged, we don't need to wait for 2.0 to release this to NPM.

@image-size image-size deleted a comment from sonarcloud bot Apr 8, 2024
@OliverSpeir
Copy link
Author

OliverSpeir commented Apr 15, 2024

or if I should keep looking for better tools for creating avif/heic/heif.

I will try to do the same, I am not too shocked to hear this didn't work I wish I could figure out how the original light_walrus.avif was created, but I'll try to also do some research

we can also use light_walrus.avif itself if we can't find a way to recreate this type of .avif

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.

None yet

2 participants