From e52cacc711020a789d98ac470203d92456729f71 Mon Sep 17 00:00:00 2001 From: HoonBaek Date: Fri, 19 Apr 2024 17:55:29 +0900 Subject: [PATCH 1/2] Add target subType to fileName in everycase --- src/utils/compressImages.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/utils/compressImages.ts b/src/utils/compressImages.ts index 550649d36..fc8c3fa8a 100644 --- a/src/utils/compressImages.ts +++ b/src/utils/compressImages.ts @@ -56,15 +56,11 @@ export const compressImage = ({ // Change the file.name & file.type for converting file type const targetFileType = outputFormat === 'preserve' ? imageFile.type : `image/${outputFormat}`; const targetSubtype = targetFileType.split('/').pop(); - let targetName = ''; const dotIndex = imageFile.name.lastIndexOf('.'); - if (dotIndex === -1) { - // No extension found, use the original filename - targetName = imageFile.name; - } else { - // Replace the old extension with the new one - targetName = imageFile.name.substring(0, dotIndex) + '.' + targetSubtype; - } + // targetName = `fileName.targetSubtype` + const targetName = `${ + dotIndex === -1 ? imageFile.name : imageFile.name.substring(0, dotIndex) + }.${targetSubtype}`; ctx.canvas.toBlob( (blob) => { if (blob) { From 31c17212ce7b49585cc426ae919468d22a79ee73 Mon Sep 17 00:00:00 2001 From: Baek EunSeo Date: Fri, 19 Apr 2024 18:14:19 +0900 Subject: [PATCH 2/2] Update src/utils/compressImages.ts Co-authored-by: Hyungu Kang | Airen --- src/utils/compressImages.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utils/compressImages.ts b/src/utils/compressImages.ts index fc8c3fa8a..79a0f199d 100644 --- a/src/utils/compressImages.ts +++ b/src/utils/compressImages.ts @@ -58,9 +58,7 @@ export const compressImage = ({ const targetSubtype = targetFileType.split('/').pop(); const dotIndex = imageFile.name.lastIndexOf('.'); // targetName = `fileName.targetSubtype` - const targetName = `${ - dotIndex === -1 ? imageFile.name : imageFile.name.substring(0, dotIndex) - }.${targetSubtype}`; + const targetName = `${dotIndex === -1 ? imageFile.name : imageFile.name.substring(0, dotIndex)}.${targetSubtype}`; ctx.canvas.toBlob( (blob) => { if (blob) {