Skip to content

Commit

Permalink
Merge pull request #32 from Eisvana/dev
Browse files Browse the repository at this point in the history
fix file extension
  • Loading branch information
Lenni009 authored Mar 31, 2024
2 parents 79ac692 + 9f6e242 commit fd3092e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion logic/compressImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ export async function compressFile(inputFile: File, quality: number = 1): Promis
const file = new File([inputFile], sanitisedFileName, { type: inputFile.type });
if (file.size < maxSize) return file; // if below 25 MB, don't do anything
const type = imageTypes.WEBP;
const newFileExtension = type.split('/').at(-1);
const res = await compressImage(file, {
quality,
type,
});
const lowerQuality = quality - 0.01; // NoSonar reduce quality by 1%;
if (res.size > maxSize) return await compressFile(file, lowerQuality); // compress original file with lower quality setting to avoid double compression
const fileName = file.name.split('.').slice(0, -1).join('.');
const newFileName = `${fileName}-min.${type}`;
const newFileName = `${fileName}-min.${newFileExtension}`;
return new File([res], newFileName, { type });
}

0 comments on commit fd3092e

Please sign in to comment.