-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (58 loc) · 1.86 KB
/
main.js
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
"use strict";
import { AddText, DrawBackground } from "./HelperFunctions.js";
let MyCanvas = document.getElementById("MyCanvas");
let ctx = MyCanvas.getContext("2d");
let AddTextButton = document.getElementById("AddTextButton");
let AddPicButton = document.getElementById("AddPicButton");
let ModelContainer = document.getElementById("ModelContainer");
let Canvas = (window.canvas = new fabric.Canvas(MyCanvas, {
// backgroundColor: "white",
// backgroundImage: "Model1.jpg",
}));
Canvas.selection = false;
Canvas.setDimensions({
width: 800,
height: 500,
});
AddTextButton.addEventListener("click", function () {
AddText("Киро Скалата", Canvas);
});
// GraveInput.addEventListener("input", function (e) {});
ModelContainer.addEventListener("click", function (e) {
if (e.target.classList.contains("Model")) {
let bgImage = window.getComputedStyle(e.target).backgroundImage;
if (bgImage && bgImage !== "none") {
bgImage = bgImage.replace(/^url\((.*?)\)$/, "$1");
bgImage = bgImage.replace(/^"(.*)"$/, "$1");
console.log("Processed Image URL:", bgImage); // Log to ensure URL is correct
DrawBackground(bgImage, Canvas);
}
}
});
document.addEventListener("keyup", function (e) {
if (e.key === "Delete") {
Canvas.remove(Canvas.getActiveObject());
}
});
AddPicButton.addEventListener("change", function (e) {
let UploadImg = e.target.files[0];
if (UploadImg) {
let reader = new FileReader();
reader.onload = function (e) {
fabric.Image.fromURL(e.target.result).then((img) => {
img.lockUniScaling = true;
img.lockScalingFlip = true;
img.hasRotatingPoint = false;
img.set({
left: 100,
top: 100,
scaleX: 0.5,
scaleY: 0.5,
});
Canvas.add(img);
Canvas.renderAll();
});
};
reader.readAsDataURL(UploadImg);
}
});