diff --git a/src/utils/ImageZipDownloader.ts b/src/utils/ImageZipDownloader.ts index f95eb97..3d7abd3 100644 --- a/src/utils/ImageZipDownloader.ts +++ b/src/utils/ImageZipDownloader.ts @@ -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(); + }; }); };