Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withoutEnlargement doesn't work when height is undefined in upload.imageSizes #9986

Open
Zhousiru opened this issue Dec 15, 2024 · 1 comment · May be fixed by #10078
Open

withoutEnlargement doesn't work when height is undefined in upload.imageSizes #9986

Zhousiru opened this issue Dec 15, 2024 · 1 comment · May be fixed by #10078
Assignees

Comments

@Zhousiru
Copy link

Describe the Bug

I want to create image sizes like 1000w, 2000w, etc., to use with srcset. I hope that when the original image size is smaller than the corresponding thumbnail width, the thumbnail won't be generated (this seems to be the behavior when withoutEnlargement is undefined)

Also, I want to keep the original image's aspect ratio. After setting the height to undefined, I encountered an issue where, regardless of the image's width, it always enlarges the image and generates thumbnails in all sizes

I tried setting withoutEnlargement to true, but this led to the creation of duplicate-sized images, which does not meet my requirements 🥲

Here is my Media.ts configuration:

import type { CollectionConfig } from 'payload'

export const Media: CollectionConfig = {
  slug: 'media',
  access: {
    read: () => true,
  },
  fields: [
    {
      name: 'alt',
      type: 'text',
      required: true,
    },
  ],
  upload: {
    imageSizes: [
      {
        name: `100w`,
        width: 100,
        height: undefined,
        withoutEnlargement: undefined,
      },
      {
        name: `4000w`,
        width: 4000,
        height: undefined,
        withoutEnlargement: undefined,
      },
    ],
    adminThumbnail: '100w',
  },
}

And reproduction repo here

Link to the code that reproduces this issue

https://github.com/Zhousiru/payload-repro-2

Reproduction Steps

  1. Launch the reproduction app
  2. Upload the test-image.jpg (600x400, available in reproduction repo) to the media collection
  3. The image was scaled to 4000x2667

And here is the screen recording:

repro.mp4

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
  Node: 20.16.0
  npm: 10.8.1
  Yarn: N/A
  pnpm: 9.15.0
Relevant Packages:
  payload: 3.7.0
  next: 15.1.0
  @payloadcms/email-nodemailer: 3.7.0
  @payloadcms/graphql: 3.7.0
  @payloadcms/next/utilities: 3.7.0
  @payloadcms/payload-cloud: 3.7.0
  @payloadcms/richtext-lexical: 3.7.0
  @payloadcms/translations: 3.7.0
  @payloadcms/ui/shared: 3.7.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Debian 6.11.9-1 (2024-11-17)
  Available memory (MB): 15998
  Available CPU cores: 12
@Zhousiru Zhousiru added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 15, 2024
@PatrikKozak PatrikKozak self-assigned this Dec 18, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Dec 18, 2024
@Zhousiru
Copy link
Author

Hi there, I provided a possible fix in #10078 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants