Showing
6 changed files
with
86 additions
and
2 deletions
gif-generator/src/components/Brush.js
0 → 100644
1 | +import ComponentInterface from "./ComponentInterface" | ||
2 | +import Color from "./Color" | ||
3 | + | ||
4 | +class Brush extends ComponentInterface { | ||
5 | + constructor(fabricObj) { | ||
6 | + super(); | ||
7 | + this.color = new Color(fabricObj.stroke); | ||
8 | + this.paths = fabricObj.path; | ||
9 | + this.size = fabricObj.strokeWidth; | ||
10 | + } | ||
11 | +} | ||
12 | + | ||
13 | +export default Brush | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
gif-generator/src/components/Color.js
0 → 100644
1 | +class Color { | ||
2 | + constructor(colorData) { | ||
3 | + if(colorData[0] == "#") { | ||
4 | + this.r = parseInt(colorData.substring(1, 3), 16) | ||
5 | + this.g = parseInt(colorData.substring(3, 5), 16) | ||
6 | + this.b = parseInt(colorData.substring(5, 7), 16) | ||
7 | + this.a = 1 | ||
8 | + } else { | ||
9 | + const rgba = colorData.substring(5, colorData.length - 1).split(","); | ||
10 | + this.r = parseInt(rgba[0]); | ||
11 | + this.g = parseInt(rgba[1]); | ||
12 | + this.b = parseInt(rgba[2]); | ||
13 | + this.a = parseFloat(rgba[3]); | ||
14 | + } | ||
15 | + } | ||
16 | +} | ||
17 | + | ||
18 | +export default Color; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
gif-generator/src/components/Text.js
0 → 100644
1 | +import ComponentInterface from "./ComponentInterface" | ||
2 | +import Color from "./Color" | ||
3 | + | ||
4 | +class Text extends ComponentInterface { | ||
5 | + constructor(fabricObj) { | ||
6 | + super(); | ||
7 | + this.color = new Color(fabricObj.fill); | ||
8 | + this.text = fabricObj.text; | ||
9 | + this.position = { | ||
10 | + top:fabricObj.top, | ||
11 | + left:fabricObj.left | ||
12 | + } | ||
13 | + this.font = { | ||
14 | + size:fabricObj.fontSize, | ||
15 | + style:fabricObj.fontStyle, | ||
16 | + weight:fabricObj.fontWeight, | ||
17 | + family:fabricObj.fontFamily | ||
18 | + } | ||
19 | + } | ||
20 | +} | ||
21 | + | ||
22 | +export default Text | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
gif-generator/src/components/index.js
0 → 100644
1 | import GIF from "gifencoder"; | 1 | import GIF from "gifencoder"; |
2 | +import {fabric} from "fabric" | ||
3 | +import Component from "./components"; | ||
2 | 4 | ||
3 | class GifGenerator { | 5 | class GifGenerator { |
4 | constructor(canvas) { | 6 | constructor(canvas) { |
... | @@ -13,17 +15,32 @@ class GifGenerator { | ... | @@ -13,17 +15,32 @@ class GifGenerator { |
13 | this.gif.setQuality(10); | 15 | this.gif.setQuality(10); |
14 | } | 16 | } |
15 | 17 | ||
16 | - addFrame(delay = 0) { | 18 | + _addFrame(delay = 0) { |
17 | this.gif.setDelay(delay); | 19 | this.gif.setDelay(delay); |
18 | this.gif.addFrame(this.canvas.getContext()); | 20 | this.gif.addFrame(this.canvas.getContext()); |
19 | } | 21 | } |
20 | 22 | ||
21 | - render() { | 23 | + _render() { |
22 | this.gif.finish(); | 24 | this.gif.finish(); |
23 | const byte = new Uint8Array(this.gif.out.data); | 25 | const byte = new Uint8Array(this.gif.out.data); |
24 | 26 | ||
25 | return new Blob([byte], { type: "image/gif" }); | 27 | return new Blob([byte], { type: "image/gif" }); |
26 | } | 28 | } |
29 | + | ||
30 | + make() { | ||
31 | + const fabricObjs = this.canvas.getObjects(); | ||
32 | + const objs = []; | ||
33 | + | ||
34 | + fabricObjs.map((fabricObj) => { | ||
35 | + if(fabricObj instanceof fabric.Path) { | ||
36 | + objs.push(new Component.Brush(fabricObj)) | ||
37 | + } else if(fabricObj.text !== undefined) { | ||
38 | + objs.push(new Component.Text(fabricObj)) | ||
39 | + } | ||
40 | + }) | ||
41 | + | ||
42 | + console.log(objs); | ||
43 | + } | ||
27 | } | 44 | } |
28 | 45 | ||
29 | window.GifGenerator = GifGenerator; | 46 | window.GifGenerator = GifGenerator; | ... | ... |
-
Please register or login to post a comment