Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Issue with Automatic Computation of Width in Upload Field Configuration

default discord avatar
mng9391last year
5

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
    last year

    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
    mng9391last year
    @967118574445547650

    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
    last year

    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
    mng9391last year

    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
    last year

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

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.