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
-
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
jpeg
with a quality of 80. This is fine, but it would be nice to have more control over this. I think addingpng
,webp
andavif
as options would be a nice start, as well as making it possible to set thequality
setting.Possible changes
Currently, image resizing is handled in
packages/core/manifest/src/storage/services/storage.service.ts
in thestoreImage
function based on theimagesSize: ImageSizesObject
parameter. One possible way to start implementing this would be to add two parameters to theImageSizesObject
type:Then, in the
storeImage
function, this could be handled something like this:Additionally, you could also consider adding a
lossless
option to thequality
parameter so the lossless options forwebp
andavif
could 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
ImageSizesObject
type: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
.resize
part 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
,medium
andlarge
, and we've setallowUpscaling = false
. When we upload an image that is smaller than thesmall
size, it would be wasteful to upload it two more times for themedium
andlarge
sizes. 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