Skip to content

feat: expose Sharp encoder config options for image generation#15804

Open
merlinnot wants to merge 5 commits intowithastro:mainfrom
merlinnot:encoder
Open

feat: expose Sharp encoder config options for image generation#15804
merlinnot wants to merge 5 commits intowithastro:mainfrom
merlinnot:encoder

Conversation

@merlinnot
Copy link
Contributor

Changes

  • Adds codec-specific defaults to Astro’s built-in Sharp image service via image.service.config
  • Supports jpeg, png, webp, and avif encoder option objects for compile-time image generation
  • Applies these config values to Sharp’s format-specific encoders while keeping per-image quality as the higher-precedence override
  • Preserves the existing animated GIF to WebP behavior, with loop: 0 remaining the default unless explicitly overridden

Testing

  • Added unit tests for codec-specific encoder option resolution
  • Verified config defaults are applied when no per-image quality is provided
  • Verified per-image quality overrides config-level quality
  • Verified jpg output maps to JPEG encoder defaults
  • Verified animated GIF to WebP keeps the default loop: 0 unless overridden in config

Docs

Added public config docs for image.service.config.jpeg, image.service.config.png, image.service.config.webp, and image.service.config.avif

/cc @withastro/maintainers-docs for feedback!

@changeset-bot
Copy link

changeset-bot bot commented Mar 8, 2026

🦋 Changeset detected

Latest commit: 57b1808

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 pkg: astro Related to the core `astro` package (scope) docs pr labels Mar 8, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 8, 2026

Merging this PR will improve performance by 10.37%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 17 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation Build: hybrid site (static + server) 8.8 s 8 s +10.37%

Comparing merlinnot:encoder (57b1808) with main (23d5244)

Open in CodSpeed

merlinnot and others added 2 commits March 11, 2026 16:12
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
@merlinnot merlinnot requested a review from Princesseuh March 11, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants