Skip to content

Commit

Permalink
Merge pull request #109 from Na-o-man/feat/#89
Browse files Browse the repository at this point in the history
Fix: 다운로드 로직 변경
  • Loading branch information
NekoGroove01 authored Aug 23, 2024
2 parents 687179e + 2480cf6 commit 35aa20e
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/utils/ImageZipDownloader.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
// 이미지들을 jpeg로 변환하여 다운로드
const imageZipDownloader = async (imageUrls: string[]) => {
imageUrls.forEach((url, index) => {
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `image-${index + 1}.jpeg`; // 파일 이름 지정
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
})
.catch((error) => console.error('Image download failed:', error));
const img = new Image();
img.crossOrigin = 'anonymous';
img.src = url;
img.onload = () => {
// create Canvas
const canvas = document.createElement('canvas');
const ctx: CanvasRenderingContext2D | null = canvas.getContext('2d');
if (!ctx) return;
canvas.width = img.width;
canvas.height = img.height;
ctx?.drawImage(img, 0, 0);
// for create tag anchor
const a = document.createElement('a');
a.download = `image-${index}-download`;
a.href = canvas.toDataURL('image/jpeg');
a.click();
};
});
};

Expand Down

0 comments on commit 35aa20e

Please sign in to comment.