Skip to content

Commit c67c323

Browse files
authored
fix: Add target subType to fileName in every case (#1070)
### Issue * it couldn't convert to the target fileType, if original file's name doesn't contain the file extension
1 parent 778aa35 commit c67c323

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/utils/compressImages.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,9 @@ export const compressImage = ({
5656
// Change the file.name & file.type for converting file type
5757
const targetFileType = outputFormat === 'preserve' ? imageFile.type : `image/${outputFormat}`;
5858
const targetSubtype = targetFileType.split('/').pop();
59-
let targetName = '';
6059
const dotIndex = imageFile.name.lastIndexOf('.');
61-
if (dotIndex === -1) {
62-
// No extension found, use the original filename
63-
targetName = imageFile.name;
64-
} else {
65-
// Replace the old extension with the new one
66-
targetName = imageFile.name.substring(0, dotIndex) + '.' + targetSubtype;
67-
}
60+
// targetName = `fileName.targetSubtype`
61+
const targetName = `${dotIndex === -1 ? imageFile.name : imageFile.name.substring(0, dotIndex)}.${targetSubtype}`;
6862
ctx.canvas.toBlob(
6963
(blob) => {
7064
if (blob) {

0 commit comments

Comments
 (0)