Issue with Automatic Computation of Width in Upload Field Configuration

default discord avatar
mng9391
3 months ago
8

I'm attempting to utilize the upload field in the following manner:


upload: { staticURL: '/images', staticDir: 'images', imageSizes: [ { name: 'large', height: 890, width: undefined, }, { name: 'small', height: 408, width: undefined }, ...

I anticipate that the width will be automatically computed based on the specified height. However, I observed that both values are returned as null.

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    This is just an issue with the data that is returned then? Are you able to see if the image file that is written is the expected dimensions?



    We shuttle these values off to sharp to handle. If you're trying to maintain the aspect ratio of the image, I believe it's the

    height

    value that needs to be set to

    undefined

    , not

    width
  • default discord avatar
    mng9391
    3 months ago

    @denolfe The issue was that the desired size was larger than the uploaded image size, which is why the image didn't get resized.


    https://github.com/payloadcms/payload/blob/38e962f2cbcaf9eaa72276969289efdbf670c7c7/src/uploads/imageResizer.ts#L129


    I would recommend to leave a note for that in the docs

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    Ah, yes this does sometimes trip people up.



    It might be worth a discussion if resizing no matter what should be the default.



    Thoughts on that?

  • default discord avatar
    mng9391
    3 months ago

    yea, I think upscaling is probably not ideal so I would leave it as is it right now.


    also, it would be great if we have an option like "forceResize"


    I can add a PR for that if you want

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    Go ahead and open a GH discussion, and we can all discuss the feature 👍

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.