You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A hook to access sharp instance for extra processing (crop, maintain EXIF, etc) #52
This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.
I already commented on the other issue report, but want to repeat the request here:
Yes, keeping image metadata like EXIF, XMP, and IPTC and also the ICC colour profile are critical for me as well.
I'm a visual artist building my website with eleventy ATM and will be unable to use the image plugin at all if I can't keep metadata and ICC profiles - my images look washed out and the contact information on the images is missing after the processing.
I would be super thankful if somebody could implement the hooks to activate/access the "withMetadata" functionality that is already in sharp: https://sharp.pixelplumbing.com/api-output#withmetadata
I am sadly not up to that myself.
Would it be bad to do something as naïve as adding a sharpHook option that takes a Sharp instance as a parameter and returns a Sharp instance. Then in img.js (maybe around line 500?) have
It's not foolproof by any means. It would allow the dev to completely override what 11ty-img is doing: one could sharp.resize(100, null) and it would ignore any resizing you've asked the plugin to do while not reporting correctly. Perhaps running the hook before everything else would be better. Still, I feel like there's some more user friendly way of doing this since this is pretty heavy-handed and permissive.
EDIT
Putting that code a bit higher does feel better. After the sharp instance clone on line 481, but before the current resize/rotate code means that any resizing the user does in the hook is overwritten by the plugin options. While that means ignoring explicit calls to resize in the hook, it feels less confusing to respect the primary options of the plugin.
I can't comment on the "would it be bad" part ;-)
But otherwise I think this could be interesting if nobody has a better and more "non-bad" solution while leaving the plugin intact otherwise.
Like a kind of "Pro-mode".
My current workaround is setting the default for "withMetadata" to "true" in the sharp/lib/constructor.js (line 261).
Dirty hack, but does what I need for the time being.
My website is almost ready now thanks to this.
But yeah, like I wrote on the other thread, IMO this is mission critical for any application of eleventy where the image IS the product.
@ScreenDream Feel free to use my fork - though I won't guarantee this will always be around, though for the moment I'll be using it until there's a solution in the main repo here (bit easier than re-writing my code to use Sharp directly).
Sounds like you're doing everything at build time though and don't need access to a proper package so your solution may be stable enough.
First of all, thanks for this great plugin - it is a really valuable tool when working with image content!
As this PR is closed: is the Feature (a hook exposing sharpInstance) being rejected? I think it would be a handy addition to the plugin, keeping it's API concise while opening possibilities for users.
Edit: ok now i get it, closed PR != rejected feature. However as i have to work with a fork of @11ty/eleventy-img: i'm looking forward for this to make it into main.
Ok, so I installed version 6.0.0-beta.2 today following your announcement on LinkedIn and while the code was accepted, I still did not have the full metadata in the output jpg, webp and avif files with the code you posted above, but when I replaced "keepExif()" with "keepMetadata()", it was all there.
AWESOME :-)
Thanks a ton!
Out of curiosity: Is this "transform: (sharp) => {...}" code a way to access everything sharp offers or is it only meant to be used for the metadata?
Activity
tusamni commentedon May 28, 2021
I'd love to be able to have a hook to access EXIF data.
colingreen commentedon Jan 14, 2022
I'd like to see this too – I want to get hold of the image's dominant colour from the Sharp stats: https://sharp.pixelplumbing.com/api-input#stats
zachleat commentedon Feb 24, 2022
ScreenDream commentedon Sep 27, 2023
I already commented on the other issue report, but want to repeat the request here:
Yes, keeping image metadata like EXIF, XMP, and IPTC and also the ICC colour profile are critical for me as well.
I'm a visual artist building my website with eleventy ATM and will be unable to use the image plugin at all if I can't keep metadata and ICC profiles - my images look washed out and the contact information on the images is missing after the processing.
I would be super thankful if somebody could implement the hooks to activate/access the "withMetadata" functionality that is already in sharp: https://sharp.pixelplumbing.com/api-output#withmetadata
I am sadly not up to that myself.
Thanks a ton!
Tom
philiprenich commentedon Oct 1, 2023
Would it be bad to do something as naïve as adding a
sharpHookoption that takes a Sharp instance as a parameter and returns a Sharp instance. Then inimg.js(maybe around line 500?) haveIt's not foolproof by any means. It would allow the dev to completely override what 11ty-img is doing: one could
sharp.resize(100, null)and it would ignore any resizing you've asked the plugin to do while not reporting correctly. Perhaps running the hook before everything else would be better. Still, I feel like there's some more user friendly way of doing this since this is pretty heavy-handed and permissive.EDIT
Putting that code a bit higher does feel better. After the sharp instance clone on line 481, but before the current resize/rotate code means that any resizing the user does in the hook is overwritten by the plugin options. While that means ignoring explicit calls to
resizein the hook, it feels less confusing to respect the primary options of the plugin.ScreenDream commentedon Oct 1, 2023
I can't comment on the "would it be bad" part ;-)
But otherwise I think this could be interesting if nobody has a better and more "non-bad" solution while leaving the plugin intact otherwise.
Like a kind of "Pro-mode".
My current workaround is setting the default for "withMetadata" to "true" in the sharp/lib/constructor.js (line 261).
Dirty hack, but does what I need for the time being.
My website is almost ready now thanks to this.
But yeah, like I wrote on the other thread, IMO this is mission critical for any application of eleventy where the image IS the product.
Thanks to everybody looking into this!
philiprenich commentedon Oct 1, 2023
@ScreenDream Feel free to use my fork - though I won't guarantee this will always be around, though for the moment I'll be using it until there's a solution in the main repo here (bit easier than re-writing my code to use Sharp directly).
Sounds like you're doing everything at build time though and don't need access to a proper package so your solution may be stable enough.
Here's how you'd use a GitHub url in your
package.jsonhansspiess commentedon Feb 11, 2024
First of all, thanks for this great plugin - it is a really valuable tool when working with image content!
As this PR is closed: is the Feature (a hook exposing
sharpInstance) being rejected? I think it would be a handy addition to the plugin, keeping it's API concise while opening possibilities for users.Edit: ok now i get it, closed PR != rejected feature. However as i have to work with a fork of
@11ty/eleventy-img: i'm looking forward for this to make it into main.smth commentedon Jun 7, 2024
I was just wondering about this. I wrote up an experiment here where I used Sharp to essentially get the background colour of an image. I called Sharp directly to do this, which feels like a doubling of work (assuming the data I generated already exists somewhere).
zachleat commentedon Dec 20, 2024
Shipping with v6.0.0-beta.1
This is a preprocessing step that runs before the Image runs orientation fix, resize, and format conversion (all of which still run afterwards)
ScreenDream commentedon Jan 2, 2025
Is 6.0.0-beta.1 available already?
I only see beta and release versions up to 5.0.0 with
npm show @11ty/eleventy-img versionsAnd will that keep both Exif metadata and ICC profiles like "keepMetadata()" does with Sharp?
https://sharp.pixelplumbing.com/api-output#keepmetadata
We are working on a new website and my old hack no longer works...
zachleat commentedon Jan 2, 2025
Not yet—finishing up some last issue triage before we release! Soon!
ScreenDream commentedon Jan 2, 2025
Awesome! Thank you! ❤️❤️❤️
ScreenDream commentedon Jan 6, 2025
Ok, so I installed version 6.0.0-beta.2 today following your announcement on LinkedIn and while the code was accepted, I still did not have the full metadata in the output jpg, webp and avif files with the code you posted above, but when I replaced "keepExif()" with "keepMetadata()", it was all there.
AWESOME :-)
Thanks a ton!
Out of curiosity: Is this "transform: (sharp) => {...}" code a way to access everything sharp offers or is it only meant to be used for the metadata?
Cheers and a great 2025 to you!
Tom
zachleat commentedon Jan 7, 2025
@ScreenDream it allows the full power of anything exposed in the Sharp api!
Support manual resize in `transform` callback hook #52 Important for …
Fixes 11ty#52 with `transform` function option.