diff --git a/src/App.jsx b/src/App.jsx index 41a064e..aa7d41f 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -59,7 +59,6 @@ function App() { } /> } /> } /> - } /> } /> } /> } /> diff --git a/src/assets/template-15.png b/src/assets/template-15.png new file mode 100644 index 0000000..813f479 Binary files /dev/null and b/src/assets/template-15.png differ diff --git a/src/assets/template-9.png b/src/assets/template-9.png new file mode 100644 index 0000000..5fc5967 Binary files /dev/null and b/src/assets/template-9.png differ diff --git a/src/component/MakeFrameCpn/Template.jsx b/src/component/MakeFrameCpn/Template.jsx index 0ad0d19..8e19c78 100644 --- a/src/component/MakeFrameCpn/Template.jsx +++ b/src/component/MakeFrameCpn/Template.jsx @@ -7,12 +7,13 @@ import template5 from "../../assets/template-5.png"; import template6 from "../../assets/template-6.png"; import template7 from "../../assets/template-7.png"; import template8 from "../../assets/template-8.png"; -// import template9 from "../../assets/template-9.png"; +import template9 from "../../assets/template-9.png"; import template10 from "../../assets/template-10.png"; import template11 from "../../assets/template-11.png"; import template12 from "../../assets/template-12.png"; import template13 from "../../assets/template-13.png"; import template14 from "../../assets/template-14.png"; +import template15 from "../../assets/template-15.png"; import styles from "./Template.module.css"; const Template = ({ changeFrameImage }) => { @@ -50,6 +51,9 @@ const Template = ({ changeFrameImage }) => { + @@ -65,6 +69,9 @@ const Template = ({ changeFrameImage }) => { + ); diff --git a/src/pages/Frame/ApplyFrame.jsx b/src/pages/Frame/ApplyFrame.jsx index d2a8907..82530b2 100644 --- a/src/pages/Frame/ApplyFrame.jsx +++ b/src/pages/Frame/ApplyFrame.jsx @@ -105,28 +105,66 @@ const ApplyFrame = () => { const frameElement = document.querySelector(`.${styles.Frame}`); frameElement.src = selectedFrame; - html2canvas(frameElement).then((canvas) => { - const context = canvas.getContext("2d"); - - const selectedFrameImg = new Image(); - selectedFrameImg.crossOrigin = "anonymous"; - selectedFrameImg.src = - selectedFrame + "?timestamp=" + new Date().getTime(); - console.log(selectedFrameImg); - selectedFrameImg.onload = () => { - context.drawImage(selectedFrameImg, 0, 0); - - // Convert canvas content to blob and save - canvas.toBlob((blob) => { - const formData = new FormData(); - formData.append("photo", blob, "frame.png"); - - const config = { - headers: { - "Content-Type": "multipart/form-data", - Authorization: `Bearer ${accessToken}`, - }, - }; + const uploadedImageElement = document.querySelector( + `.${styles.UploadedImage}` + ); + + const uploadedImageWidth = uploadedImageElement.clientWidth; + const uploadedImageHeight = uploadedImageElement.clientHeight; + + const canvas = document.createElement("canvas"); + canvas.width = uploadedImageWidth; + canvas.height = uploadedImageHeight; + const context = canvas.getContext("2d"); + + const selectedFrameImg = new Image(); + selectedFrameImg.crossOrigin = "anonymous"; + selectedFrameImg.src = + selectedFrame + "?timestamp=" + new Date().getTime(); + + const uploadedImage = new Image(); + uploadedImage.crossOrigin = "anonymous"; + uploadedImage.src = uploadedImageElement.src; + + Promise.all([ + new Promise((resolve) => { + selectedFrameImg.onload = () => { + resolve(); + }; + }), + new Promise((resolve) => { + uploadedImage.onload = () => { + resolve(); + }; + }), + ]).then(() => { + context.drawImage( + uploadedImage, + 0, + 0, + uploadedImageWidth, + uploadedImageHeight + ); + + context.drawImage( + selectedFrameImg, + 0, + 0, + uploadedImageWidth, + uploadedImageHeight + ); + + // Convert canvas content to blob and save + canvas.toBlob((blob) => { + const formData = new FormData(); + formData.append("photo", blob, "frame.png"); + + const config = { + headers: { + "Content-Type": "multipart/form-data", + Authorization: `Bearer ${accessToken}`, + }, + }; axios .post( diff --git a/src/pages/Frame/ApplyFrame.module.css b/src/pages/Frame/ApplyFrame.module.css index 0a23f61..3c41523 100644 --- a/src/pages/Frame/ApplyFrame.module.css +++ b/src/pages/Frame/ApplyFrame.module.css @@ -60,7 +60,7 @@ button { .Middle { width: 390px; - height: 479px; + flex: 1; display: inline-block; flex-direction: column; justify-content: center; @@ -71,7 +71,7 @@ button { .MiddleTop { width: 390px; - height: 49px; + height: 50px; background-color: #ffffff; } @@ -103,6 +103,9 @@ button { .UploadedImage { position: absolute; + top: 0; + left: 50%; + transform: translateX(-50%); z-index: 1; } diff --git a/src/pages/Frame/MakeFrame.jsx b/src/pages/Frame/MakeFrame.jsx index 8c0d066..bd30296 100644 --- a/src/pages/Frame/MakeFrame.jsx +++ b/src/pages/Frame/MakeFrame.jsx @@ -300,37 +300,64 @@ const MakeFrame = () => { const frameElement = document.querySelector(`.${styles.Frame}`); html2canvas(frameElement, { backgroundColor: null }).then((canvas) => { - canvas.toBlob((blob) => { - const formData = new FormData(); - formData.append("frame", blob, "frame.png"); - - console.log(formData); - - // axios 요청 설정 - const config = { - headers: { - "Content-Type": "multipart/form-data", - Authorization: `Bearer ${accessToken}`, // 헤더에 accessToken을 추가 - }, - }; - - axios - .post( - "http://ec2-3-35-208-177.ap-northeast-2.compute.amazonaws.com:8080/frame", - formData, - config - ) - .then((res) => { - console.log("프레임 저장 API 응답:", res.data); - const updatedFrames = [...frames, res.data]; // 새로운 데이터 추가 - setFrames(updatedFrames); - return ; - }) - .catch((err) => { - // 오류 처리 - console.error("API 요청 중 오류 발생:", err); - }); - }, "image/png"); + const ctx = canvas.getContext("2d"); + + const stickerImagePromises = selectedStickers.map((selectedSticker) => { + return new Promise((resolve) => { + const stickerImg = new Image(); + stickerImg.crossOrigin = "anonymous"; // Set cross-origin attribute + stickerImg.onload = () => resolve(stickerImg); + stickerImg.src = + selectedSticker + "?timestamp=" + new Date().getTime(); + }); + }); + + Promise.all(stickerImagePromises).then((loadedStickerImages) => { + loadedStickerImages.forEach((stickerImg, index) => { + const stickerPos = stickerPositions[index]; + if (stickerPos) { + ctx.drawImage( + stickerImg, + stickerPos.x, + stickerPos.y, + stickerSize, + stickerSize + ); + } + }); + + canvas.toBlob((blob) => { + const formData = new FormData(); + formData.append("frame", blob, "frame.png"); + + console.log(formData); + + // axios 요청 설정 + const config = { + headers: { + "Content-Type": "multipart/form-data", + Authorization: `Bearer ${accessToken}`, // 헤더에 accessToken을 추가 + }, + }; + + axios + .post( + "http://ec2-3-35-208-177.ap-northeast-2.compute.amazonaws.com:8080/frame", + formData, + config + ) + .then((res) => { + console.log("프레임 저장 API 응답:", res.data); + const updatedFrames = [...frames, res.data]; // 새로운 데이터 추가 + setFrames(updatedFrames); + return ; + }) + .catch((err) => { + // 오류 처리 + console.error("API 요청 중 오류 발생:", err); + }); + }, "image/png"); + }); }); } }; @@ -465,20 +492,15 @@ const MakeFrame = () => { /> ))} -
- -
-
- {bottomContent} +
+
+
{bottomContent}