Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
MAC_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이정민
2021-05-20 00:15:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
fb39548ccc3ac12f2bcaf2419b4a029c7efc190d
fb39548c
1 parent
f00acdde
TuiImageEditor 객체
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
63 deletions
src/components/GifEditor.tsx
src/components/GifEditor.tsx
View file @
fb39548
import { useEffect, useRef, useState } from "react";
import { fabric } from "fabric";
import styled from "styled-components";
import { GifGenerator } from "gif-generator/src";
import
ImageEditor from "@toast-ui/react
-image-editor";
import
TuiImageEditor from "tui
-image-editor";
const GifEditor = ({ previewURL }) => {
const [canvas, setCanvas] = useState<HTMLCanvasElement>();
const [gifGenerator, setGifGenerator] = useState(null);
// const [canvas, setCanvas] = useState<HTMLCanvasElement>();
// const [gifGenerator, setGifGenerator] = useState(null);
const [imageEditor, setImageEditor] = useState(null);
const rootEl = useRef();
useEffect(() => {
// if (window) {
// setCanvas(
// document.getElementsByClassName(
// "tui-image-editor-container"
// )[0] as HTMLCanvasElement
// );
// console.log(
// document.getElementsByClassName(
// "tui-image-editor-container"
// )[0] as HTMLCanvasElement
// );
// }
if (window) {
setCanvas(
document.getElementsByClassName(
"tui-image-editor-container"
)[0] as HTMLCanvasElement
setImageEditor(
new TuiImageEditor(rootEl.current, {
includeUI: {
loadImage: {
path: previewURL,
name: "SampleImage",
},
uiSize: {
width: "100%",
height: "600px",
},
initMenu: "filter",
menuBarPosition: "bottom",
},
cssMaxWidth: 500,
cssMaxHeight: 700,
usageStatistics: false,
})
);
}
}, []);
console.log(
"asdf",
document.getElementsByClassName("tui-image-editor-container")
);
console.log("canvas", canvas);
console.log('useref',useRef.arguments)
useEffect(()=>{
if(canvas)setGifGenerator(new GifGenerator(canvas._graphics.getCanvas()));
}, [canvas])
useEffect(() => {
if (imageEditor) {
// setGifGenerator(new GifGenerator(imageEditor._graphics.getCanvas()));
console.log(imageEditor._graphics.getCanvas().getObjects());
}
}, [imageEditor]);
const render = () => {
console.log("aaa", imageEditor._graphics.getCanvas().getObjects());
const gifGenerator = new GifGenerator(imageEditor._graphics.getCanvas());
gifGenerator.make().then(
(blob) => {
window.open(window.URL.createObjectURL(blob));
},
(error) => {
alert(error);
}
);
};
// useEffect(() => {
// // if (canvas) setGifGenerator(new GifGenerator(canvas._graphics.getCanvas()));
// if (canvas) {
// console.log("aaaaa", canvas);
// }
// }, [canvas]);
// useEffect(() => {
// if (window) {
// setCanvas(document.getElementById("gif-canvas") as HTMLCanvasElement);
// }
// }, []);
// useEffect(() => {
// // const img = lowerCanvas?.toDataURL("image/png");
...
...
@@ -43,7 +95,7 @@ const GifEditor = ({ previewURL }) => {
// image.src = previewURL;
// console.log("canvascontext", canvas?.getContext);
// if (canvas?.getContext) {
// console.log(
'왜안돼')
// console.log(
"왜안돼");
// image.onload = function () {
// canvas.width = 1000;
// canvas.height = 572;
...
...
@@ -53,55 +105,47 @@ const GifEditor = ({ previewURL }) => {
// }
// }, [canvas]);
const render = () => {
gifGenerator.make().then(
(blob) => {
window.open(window.URL.createObjectURL(blob));
},
(error) => {
alert(error);
}
);
};
return (
<Container>
<div onClick={render} className="upload">
Save
</div>
<ImageEditor
includeUI={{
loadImage: {
path: previewURL,
name: "SampleImage",
},
menu: ["draw", "text"],
initMenu: "draw",
uiSize: {
width: "100%",
height: "600px",
},
menuBarPosition: "bottom",
}}
cssMaxHeight={500}
cssMaxWidth={700}
selectionStyle={{
cornerSize: 20,
rotatingPointOffset: 70,
}}
usageStatistics={true}
/>
<div className="alert">Please select a photo.</div>
</Container>
// <Container>
// <ImgBox>
// <canvas id="gif-canvas" />
// </ImgBox>
// </Container>
<>
<Wrapper>
<div onClick={render} className="upload">
Save
</div>
{/* <ImageEditor
includeUI={{
loadImage: {
path: previewURL,
name: "SampleImage",
},
menu: ["draw", "text"],
initMenu: "draw",
uiSize: {
width: "100%",
height: "600px",
},
menuBarPosition: "bottom",
}}
cssMaxHeight={500}
cssMaxWidth={700}
selectionStyle={{
cornerSize: 20,
rotatingPointOffset: 70,
}}
usageStatistics={true}
/> */}
<div ref={rootEl} />
<div className="alert">Please select a photo.</div>
</Wrapper>
{/* <Container>
<ImgBox>
<canvas id="gif-canvas" />
</ImgBox>
</Container> */}
</>
);
};
const
Contain
er = styled.div`
const
Wrapp
er = styled.div`
position: fixed;
width: 90%;
top: 10rem;
...
...
@@ -145,4 +189,25 @@ const Container = styled.div`
}
`;
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;
...
...
Please
register
or
login
to post a comment