Skip to content

Commit c417e3a

Browse files
authored
fix: avif images not converting to upload.formatOptions set file types (#11505)
Previously, AVIF images were not converted to other file types as expected, despite `upload.formatOptions` specifying a different file type. The issue was due to `canResizeImage` not recognizing `'image/avif',` causing `fileSupportsResize` to return `false` and preventing the image from undergoing format conversion. This fix updates `canResizeImage` to include `'image/avif'`, ensuring that AVIF images are processed correctly and converted to a different file type when specified in `formatOptions`. Fixes #10694 Fixes #9985
1 parent efce154 commit c417e3a

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export function canResizeImage(mimeType: string): boolean {
2-
return ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/tiff'].indexOf(mimeType) > -1
2+
return (
3+
['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/tiff', 'image/avif'].indexOf(
4+
mimeType,
5+
) > -1
6+
)
37
}

test/uploads/e2e.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ describe('Uploads', () => {
223223
await saveDocAndAssert(page)
224224
})
225225

226+
test('should properly convert avif image to png', async () => {
227+
await page.goto(mediaURL.create)
228+
229+
await page.setInputFiles('input[type="file"]', path.resolve(dirname, './test-image-avif.avif'))
230+
const filename = page.locator('.file-field__filename')
231+
await expect(filename).toHaveValue('test-image-avif.avif')
232+
233+
await saveDocAndAssert(page)
234+
235+
const fileMetaSizeType = page.locator('.file-meta__size-type')
236+
await expect(fileMetaSizeType).toHaveText(/image\/png/)
237+
})
238+
226239
test('should create animated file upload', async () => {
227240
await page.goto(animatedTypeMediaURL.create)
228241

test/uploads/test-image-avif.avif

495 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)