Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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