Skip to content

Fix JPEG image size determination#12542

Merged
ematipico merged 2 commits intowithastro:mainfrom
kadykov:jpeg-size
Nov 27, 2024
Merged

Fix JPEG image size determination#12542
ematipico merged 2 commits intowithastro:mainfrom
kadykov:jpeg-size

Conversation

@kadykov
Copy link
Copy Markdown
Contributor

@kadykov kadykov commented Nov 27, 2024

Fixes #12530

Changes

  • Fixed incorrect handling of non-0xFF blocks in the JPEG image size calculation. Instead of skipping one byte, the entire block is now skipped, improving performance and accuracy.
  • Before this change, the code would incorrectly enter and parse non-0xFF blocks, leading to incorrect image size determination. This change ensures that only valid JPEG blocks are processed, skipping unnecessary metadata blocks.

Testing

This change was tested manually by verifying that the image size calculation is accurate for JPEG images with various metadata blocks. No new tests were added, as the existing tests should cover this scenario.

Docs

This change does not affect user behavior, so no documentation updates are required. The fix is internal to the JPEG image size calculation logic and does not introduce any new features or APIs.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Nov 27, 2024

🦋 Changeset detected

Latest commit: 6c4ad21

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Nov 27, 2024
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Nov 27, 2024

CodSpeed Performance Report

Merging #12542 will not alter performance

Comparing kadykov:jpeg-size (6c4ad21) with main (cf0d8b0)

Summary

✅ 6 untouched benchmarks

@Princesseuh
Copy link
Copy Markdown
Member

Princesseuh commented Nov 27, 2024

This folder is a vendored version of image-size (we have not written any of the code in it), I would suggest sending a PR there as well: https://github.com/image-size/image-size

Since the upstream package here is rarely updated, it should be fine to update our copy, though

Comment thread packages/astro/src/assets/utils/vendor/image-size/types/jpg.ts
Copy link
Copy Markdown
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

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

Code looks great, thank you!

@ematipico ematipico merged commit 65e50eb into withastro:main Nov 27, 2024
@astrobot-houston astrobot-houston mentioned this pull request Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect image size determination with inferRemoteSize() or inferSize=true when JPEG image has specific metadata

3 participants