-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(sharp): add kernel option to image service config #15171
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 80f6b52 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 |
Princesseuh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's ok with me! I think people will inevitably ask to be able to set it per image, but I'd rather we start with just this for now.
sarah11918
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this new feature, @mark-ignacio !
The sharp image service isn't really documented in the docs, so uh...
I'm going to tag @ArmandPhilippot in on this one, because we do document image.service (and image.service.config.limitInputPixels in our configuration reference. We say that you need to configure an entrypoint and optionally a config, but then we only document one config item. (And, I honestly don't know whether there are more that we don't.)
My gut says that we probably do want to include this alongside limitInputPixels, in which case, this would be a new JSDoc entry in the public types file, but I'll let @ArmandPhilippot and @Princesseuh make the call on that.
As for the changeset, comment below!
| 'astro': minor | ||
| --- | ||
|
|
||
| Adds kernel option to select resize algorithm in the sharp image service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lucky you, this is a minor feature so... that means time to hype! 🥳
For a minor release of a new feature, we'd usually hype it up a bit more, focusing on what a user can now do (with an example usage shown) rather than implementation details. You can see a model of this in our contributing docs:
- Quick sentence to shout "New! Shiny!" and grab people's attention without a lot of visual clutter
- describe the problem it solves or ability it unlocks and why that's cool
- show an example that people could copy into their projects right away to try it out so that it's easy for them to get started
- link to the docs for the new thing
So maybe something like... (just rough wording to get the idea of the structure across! This will likely need correcting as I don't know how to use all the relevant vocab properly)
| Adds kernel option to select resize algorithm in the sharp image service | |
| Adds a new `kernel` configuration option to select a resize algorithm in the Sharp image service | |
| By default, Sharp's resizes uses the `lanczos3` downsizing kernal. This property allows you to configure your default resizing algorithm with any resizing option supported by Sharp](https://sharp.pixelplumbing.com/api-resize/#resize) (e.g. `linear`, `mks2021`). | |
| Resize kernel selection can produce quite noticeable differences depending on various characteristics of the source image, so this gives you more control over the appearance of images on your site: | |
| ``` | |
| export default defineConfig({ | |
| image: { | |
| service: { | |
| entrypoint: 'astro/assets/services/sharp', | |
| config: { | |
| kernel: "mks2021" | |
| } | |
| } | |
| }) | |
| ``` | |
| This selection will apply to all images on your site, and is not configurable on a per-image basis. For more information, see [Sharps documentation on resizing images](https://sharp.pixelplumbing.com/api-resize/#resize). |
(alternatively, if we do document this, then the "for more info" link should go to our own docs reference entry)
|
Sarah's suggestion makes sense to me! astro/packages/astro/src/types/public/config.ts Lines 1301 to 1314 in 27d7ffb
|
Changes
Adds a
kerneloption to the default sharp image service to allow selecting something other than the defaultlanczos3. Resize kernel selection can be quite noticeable depending on various characteristics of the source image - you can see some examples in https://johncostella.com/magic/Testing
Tested manually using
pnpm linkto a separate repository and adding a dumb littleconsole.log(), modifying the kernel property inside of config.Docs
The sharp image service isn't really documented in the docs, so uh...
/cc @withastro/maintainers-docs for feedback!