mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 23:24:03 +00:00
fix: add sizeInBytes on resized and optimized images (#19707)
This commit is contained in:
parent
79074de5e0
commit
836f74517f
@ -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),
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user