Repository navigation
Allow relationship fields to define image resize/crop options #15866
kpc2
started this conversation in
Feature Requests & Ideas
Replies: 1 comment
|
The suggested approach would be extremely helpful, especially when migrating from another headless CMS like Prismic, which supports multiple image variants per-field with their own crop options. |
0 replies
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.
Currently, if you want Payload to handle image cropping, there are two approaches for organizing media that I am aware of:
Single collection for all images with global imageSizes options
This approach is convenient because it provides a single source of truth for all media. However, it is wasteful in terms of storage and compute power, since every uploaded image is cropped and resized for every possible use case—even ones that may never be needed.
Separate collection for each use case
This approach saves space because each collection can have tailored imageSizes options. The downside is increased clutter in the admin UI, and you may need to upload the same image multiple times if it is needed in more than one situation.
I propose a third approach, which was briefly discussed in this Discord thread from two years ago, that could combine the best of both worlds:
In this approach, images are stored in a single collection, but cropping/resizing only occurs when the image is added to a relationship field. Each relationship field could define its own imageSizes options. This could avoid unnecessary crops and resizes, saving both storage and compute resources, while maintaining a single source of truth for original images.
The only missing piece in Payload currently is the ability for a relationship field to specify imageSizes when pointing to a media collection. Payload could also adopt a filename convention similar to other image processing services so that if an image has already been cropped/resized for one field, it doesn’t need to be regenerated if another has the same settings (other than the name field in imageSizes).
All reactions