Allow dynamic formatOptions
for image upload.
#3292
AF111
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've encountered a use case for applying dynamic options to Sharp based on the image format I'm uploading. I wanted to upload an image and provide custom options to Sharp. There is currently no way to do this, and with the way image size configs are specified, you have to provide this statically ahead of time. Sharp's toFormat method expects you to provide the output image format.
Now, this is fine for a use case where you want to force the resized image output to a specific format and don't care about the original uploading image's format. But what if you don't want to force output to a specific format and instead use the exact format of the same file that is uploading then conditionally apply dynamic options based on that format?
Here's what this could look like:
formatOptions
would have a discriminated union of the below signatures.Inside the image sizes config in the Collection definition. You could still specify the standard formatOptions or one that is dynamic.
Static (Current)
Dynamic (New)
Having dynamic options is also important as Sharp has different options depending on the format, and with a dynamic approach like this, you could conditionally return the correct options config based on the format. It would allow easier customization of the output for the resized images and tap into Sharp.
Here's also a related enhancement for the official cloud storage plugin that incorrectly defaults to the main upload file format.
Beta Was this translation helpful? Give feedback.
All reactions