Skip to content

Commit

Permalink
fix: Add target subType to fileName in every case (#1070)
Browse files Browse the repository at this point in the history
### Issue
* it couldn't convert to the target fileType, if original file's name
doesn't contain the file extension
  • Loading branch information
HoonBaek authored Apr 19, 2024
1 parent 778aa35 commit c67c323
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/utils/compressImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,9 @@ 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) {
Expand Down

0 comments on commit c67c323

Please sign in to comment.