Improve flexibility when resizing images #399
RamonMeffert
started this conversation in
Feature request
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.
-
Hi! Great project, I'm really enjoying it so far!
I'd like to propose some improvements to the image upload functionality.
File formats
Currently, all images are converted to
jpegwith a quality of 80. This is fine, but it would be nice to have more control over this. I think addingpng,webpandavifas options would be a nice start, as well as making it possible to set thequalitysetting.Possible changes
Currently, image resizing is handled in
packages/core/manifest/src/storage/services/storage.service.tsin thestoreImagefunction based on theimagesSize: ImageSizesObjectparameter. One possible way to start implementing this would be to add two parameters to theImageSizesObjecttype:export type ImageSizesObject = { [key: string]: { width?: number height?: number + quality?: number + format?: 'jpeg' | `png` | 'webp' | 'avif' fit?: 'contain' | 'cover' | 'fill' | 'inside' | 'outside' } }Then, in the
storeImagefunction, this could be handled something like this:Additionally, you could also consider adding a
losslessoption to thequalityparameter so the lossless options forwebpandavifcould be utilized.Resizing
Currently, images are up- or downsampled depending on the image sizes requested. While there is certainly a use case for this behavior, sometimes it is preferable to not do upsizing. In other cases, it might be preferable to keep the image as-is, e.g. when providing the option to save the original size of the image.
Possible changes: prevent upscaling
This could be added as an extra parameter to the
ImageSizesObjecttype:export type ImageSizesObject = { [key: string]: { width?: number height?: number + allowUpscaling?: boolean fit?: 'contain' | 'cover' | 'fill' | 'inside' | 'outside' } }When this parameter is set to true, the
.resizepart of the image pipeline should be skipped:Note
An additional improvement here would be to skip unnecessary duplicates. For example, let's say we have three image sizes,
small,mediumandlarge, and we've setallowUpscaling = false. When we upload an image that is smaller than thesmallsize, it would be wasteful to upload it two more times for themediumandlargesizes. Rather, we can just setPossible changes: save original image size
This could also be an extra option:
export type ImageSizesObject = { [key: string]: { width?: number height?: number + saveOriginalSize?: boolean fit?: 'contain' | 'cover' | 'fill' | 'inside' | 'outside' } }With a similar implementation to the previous suggestion:
Let me know what you think! I wouldn't mind working on this, though I would need some pointers since this would also impact the manifest schema, which I've ignored in my example implementations above.
Beta Was this translation helpful? Give feedback.
All reactions