fix: add sizeInBytes on resized and optimized images (#19707)

This commit is contained in:
Giulio Montagner 2024-03-07 18:31:55 +01:00 committed by GitHub
parent 79074de5e0
commit 836f74517f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 2 deletions

View File

@ -96,6 +96,7 @@ describe('Upload', () => {
ext: '.png',
mime: 'image/png',
size: expect.any(Number),
sizeInBytes: expect.any(Number),
width: expect.any(Number),
height: expect.any(Number),
url: expect.any(String),

View File

@ -139,6 +139,7 @@ describe('Upload plugin', () => {
ext: '.png',
mime: 'image/png',
size: expect.any(Number),
sizeInBytes: expect.any(Number),
width: expect.any(Number),
height: expect.any(Number),
url: expect.any(String),

View File

@ -59,7 +59,7 @@ const resizeFileTo = async (file, options, { name, hash }) => {
const { width, height, size } = await getMetadata(newFile);
Object.assign(newFile, { width, height, size: bytesToKbytes(size) });
Object.assign(newFile, { width, height, size: bytesToKbytes(size), sizeInBytes: size });
return newFile;
};
@ -112,13 +112,14 @@ const optimize = async (file) => {
if (newSize > size) {
// Ignore optimization if output is bigger than original
return { ...file, width, height, size: bytesToKbytes(size) };
return { ...file, width, height, size: bytesToKbytes(size), sizeInBytes: size };
}
return Object.assign(newFile, {
width: newWidth,
height: newHeight,
size: bytesToKbytes(newSize),
sizeInBytes: newSize,
});
};