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

A hook to access sharp instance for extra processing (crop, maintain EXIF, etc) #52

Closed
zachleat opened this issue Jan 21, 2021 · 8 comments
Labels
enhancement New feature or request needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.

Comments

@zachleat
Copy link
Member

See https://twitter.com/ericvalois/status/1352203081304436738

@zachleat zachleat added the enhancement New feature or request label Jan 21, 2021
@tusamni
Copy link

tusamni commented May 28, 2021

I'd love to be able to have a hook to access EXIF data.

@zachleat zachleat pinned this issue Jul 19, 2021
@colingreen
Copy link

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 zachleat added the needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. label Feb 24, 2022
@zachleat
Copy link
Member Author

This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.

View the enhancement backlog here. Don’t forget to upvote the top comment with 👍!

@ScreenDream
Copy link

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
Copy link

philiprenich commented Oct 1, 2023

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

        if(typeof this.options.sharpHook === "function") {
          sharpInstance = this.options.sharpHook(sharpInstance);
        }

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.

@ScreenDream
Copy link

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
Copy link

@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.json

@hansspiess
Copy link

hansspiess commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.
Projects
None yet
Development

No branches or pull requests

6 participants