GifEditor.tsx
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { useEffect, useState } from "react";
import { fabric } from "fabric";
import styled from "styled-components";
const GifEditor = ({ previewURL }) => {
const [canvas, setCanvas] = useState<HTMLCanvasElement>();
useEffect(() => {
if (window) {
setCanvas(document.getElementById("gif-canvas") as HTMLCanvasElement);
}
}, []);
useEffect(() => {
// const img = lowerCanvas?.toDataURL("image/png");
// const uploaded = document.getElementById("image");
// console.log(uploaded);
// let w = window.open();
// if (w?.window) w.document.body.innerHTML = "<img src='" + img + "'>";
const image = new Image();
// image.onload = function () {
// lowerCanvas.width = uploaded.clientWidth;
// lowerCanvas.height = uploaded.clientHeight;
// lowerCanvas?.getContext("2d").drawImage(image, 0, 0);
// };
console.log("fdasdafs", previewURL);
image.src = previewURL;
console.log("canvas", canvas);
if (canvas?.getContext) {
image.onload = function () {
canvas.width = 1000;
canvas.height = 572;
canvas?.getContext("2d").drawImage(image, 0, 0);
};
console.log(canvas.getContext("2d"));
}
}, [canvas]);
return (
<Container>
<ImgBox>
<canvas id="gif-canvas" />
</ImgBox>
</Container>
);
};
const Container = styled.div`
width: 100%;
display: flex;
justify-content: center;
margin-top: 10rem;
`;
const ImgBox = styled.div`
position: relative;
width: 90%;
background-color: white;
box-shadow: ${({ theme }) => theme.boxShadow.normal};
border-radius: 2rem;
margin-top: 2rem;
display: flex;
align-items: center;
justify-content: center;
font-size: 1rem;
display: flex;
padding: 1rem 0;
`;
export default GifEditor;