Toy 프로젝트로 Meme Maker 서비스를 개발중이다.
대단한것은 아니고... "짤방"메이커 서비스다.
5시간 정도 만진 것 같다.
아직은 CSS를 적용하지않아 에디터 디자인이 엉망이다.
글자의 위치, 서체, 크기, 색상을 설정할 수 있다.
다운로드 버튼을 누르면 다운로드도 가능하다.
HTML canvas 태그를 이용하여 만든다.
<Canvas className="canvas" width="770px" height="480px">
{
(window.onload = function (e: any) {
let content = document.querySelector(".canvas") as HTMLCanvasElement;
let ctx: any = content.getContext("2d");
let img = new Image();
img.src = picture3;
img.onload = function (e: any) {
ctx.drawImage(img, 0, 0, 775, 480);
};
})
}
</Canvas>
function writeText(option: string) {
let content = document.querySelector(".canvas") as HTMLCanvasElement;
let ctx: any = content.getContext("2d");
if (option === "write") {
ctx.fillStyle = fontColor;
ctx.font = `${fontSize} ${font}`;
ctx.fillText(text, x, y);
}
if (option === "delete") {
window.location.reload();
}
}
<a href="#" className="download" download onClick={downloadImg}>
function downloadImg() {
let canvas: any = document.querySelector(".canvas");
let el: any = document.querySelector(".download");
let img = canvas.toDataURL("image/jpg");
el.href = img;
}
내일은, 반응형을 손보고 로직을 마무리해야겠다.
(+)타입을 any로 지정한것도 바꿔줘야지..