appscms-tools-theme 5.2.0 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/_data/.DS_Store +0 -0
- data/_data/aitools/en/instagram-hashtag-generator.json +2 -17
- data/_data/contenttool/en/features.json +18 -243
- data/_data/header/en/data.json +4 -0
- data/_includes/.DS_Store +0 -0
- data/_includes/aitools/instagram-hashtag-generator.html +0 -0
- data/_includes/contenttool_banner.html +266 -0
- data/_includes/contenttool_result_banner.html +135 -0
- data/_layouts/appscms-download.html +110 -99
- data/_layouts/appscms-feature.html +94 -77
- data/assets/.DS_Store +0 -0
- data/assets/js/TopScroll.js +8 -0
- data/assets/js/adBlocker.js +68 -0
- data/assets/js/ads.js +8 -0
- data/assets/js/append-div.js +10 -0
- data/assets/js/appscms-infographics.js +0 -0
- data/assets/js/appscms-login.js +447 -0
- data/assets/js/appscms-search-home1.js +136 -0
- data/assets/js/appscms-search.js +133 -0
- data/assets/js/appscms-theme.js +459 -0
- data/assets/js/batch.js +219 -0
- data/assets/js/calculator-tooltip.js +3 -0
- data/assets/js/devtools.js +82 -0
- data/assets/js/face-api.js +38064 -0
- data/assets/js/face-detection.js +303 -0
- data/assets/js/faceSystem.js +0 -0
- data/assets/js/featureResult.js +48 -0
- data/assets/js/frame.js +264 -0
- data/assets/js/googledrive.js +158 -0
- data/assets/js/homeResult.js +37 -0
- data/assets/js/manifest.json +17 -0
- data/assets/js/models/age_gender_model-shard1 +0 -0
- data/assets/js/models/age_gender_model-weights_manifest.json +1 -0
- data/assets/js/models/face_expression_model-shard1 +0 -0
- data/assets/js/models/face_expression_model-weights_manifest.json +1 -0
- data/assets/js/models/face_landmark_68_model-shard1 +0 -0
- data/assets/js/models/face_landmark_68_model-weights_manifest.json +1 -0
- data/assets/js/models/face_landmark_68_tiny_model-shard1 +0 -0
- data/assets/js/models/face_landmark_68_tiny_model-weights_manifest.json +1 -0
- data/assets/js/models/face_recognition_model-shard1 +0 -0
- data/assets/js/models/face_recognition_model-shard2 +6 -0
- data/assets/js/models/face_recognition_model-weights_manifest.json +1 -0
- data/assets/js/models/mtcnn_model-shard1 +0 -0
- data/assets/js/models/mtcnn_model-weights_manifest.json +1 -0
- data/assets/js/models/ssd_mobilenetv1_model-shard1 +0 -0
- data/assets/js/models/ssd_mobilenetv1_model-shard2 +145 -0
- data/assets/js/models/ssd_mobilenetv1_model-weights_manifest.json +1 -0
- data/assets/js/models/tiny_face_detector_model-shard1 +0 -0
- data/assets/js/models/tiny_face_detector_model-weights_manifest.json +1 -0
- data/assets/js/multiselect.js +185 -0
- data/assets/js/partytown/debug/partytown-atomics.js +929 -0
- data/assets/js/partytown/debug/partytown-media.js +374 -0
- data/assets/js/partytown/debug/partytown-sandbox-sw.js +920 -0
- data/assets/js/partytown/debug/partytown-sw.js +59 -0
- data/assets/js/partytown/debug/partytown-ww-atomics.js +2699 -0
- data/assets/js/partytown/debug/partytown-ww-sw.js +2691 -0
- data/assets/js/partytown/debug/partytown.js +114 -0
- data/assets/js/partytown/partytown-atomics.js +600 -0
- data/assets/js/partytown/partytown-media.js +2 -0
- data/assets/js/partytown/partytown-sw.js +50 -0
- data/assets/js/perspective.min.js +182 -0
- data/assets/js/photo-effects.json +85 -0
- data/assets/js/redirectResult.js +10 -0
- data/assets/js/sharePage.js +65 -0
- data/assets/js/testing-batch.js +39 -0
- data/assets/js/theme.js +104 -0
- data/assets/js/usageTracking.js +143 -0
- data/assets/js/usageTrackingEvents.js +6 -0
- data/assets/js/userUsageCount.js +0 -0
- data/assets/js/webvitals.js +5 -0
- metadata +65 -3
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
const getScript = document.currentScript
|
|
2
|
+
const pageTool = getScript.dataset.tool
|
|
3
|
+
const lang = getScript.dataset.lang
|
|
4
|
+
const inputBox = document.querySelector('#Inputbox')
|
|
5
|
+
const fileDropBox = document.querySelector('.custom-box')
|
|
6
|
+
const cropModal = document.querySelector('.crop-image-modal-container')
|
|
7
|
+
const exampleModal = document.querySelector('.example-images-modal-container')
|
|
8
|
+
const workspace = document.getElementById('workspace')
|
|
9
|
+
const canvasPanel = document.getElementById('canvas-panel')
|
|
10
|
+
const download = document.querySelector('#download-button')
|
|
11
|
+
const form = document.querySelector('#effect-form')
|
|
12
|
+
let files = []
|
|
13
|
+
let cropWidth = null
|
|
14
|
+
let cropHeight = null
|
|
15
|
+
let cropper = null
|
|
16
|
+
let cropInputWidth = null
|
|
17
|
+
let index = 0
|
|
18
|
+
let cropInputHeight = null
|
|
19
|
+
let image = null
|
|
20
|
+
const showLoader = () => {
|
|
21
|
+
showLoading()
|
|
22
|
+
}
|
|
23
|
+
const closeLoader = () => {}
|
|
24
|
+
const clickInput = (e) => {
|
|
25
|
+
console.log(`#file-${e.dataset.index}`)
|
|
26
|
+
document.querySelector(`#file-${e.dataset.index}`).click()
|
|
27
|
+
}
|
|
28
|
+
let featureData = null
|
|
29
|
+
|
|
30
|
+
fetch('/assets/js/photo-effects.json')
|
|
31
|
+
.then((response) => response.json())
|
|
32
|
+
.then((data) => {
|
|
33
|
+
featureData = data.find((i) => i.name === form.dataset.featureName)
|
|
34
|
+
console.log(featureData)
|
|
35
|
+
})
|
|
36
|
+
const fileOnChange = (e) => {
|
|
37
|
+
index = Number(e.dataset.index)
|
|
38
|
+
let reader = new FileReader()
|
|
39
|
+
reader.onload = (event) => {
|
|
40
|
+
cropModal.style.display = 'flex'
|
|
41
|
+
if (cropper === null) {
|
|
42
|
+
cropImage(event.target.result, e.id)
|
|
43
|
+
} else {
|
|
44
|
+
updateCropper(event.target.result, e.id)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
reader.readAsDataURL(e.files[0])
|
|
48
|
+
}
|
|
49
|
+
const closeModal = () => {
|
|
50
|
+
cropModal.style.display = 'none'
|
|
51
|
+
}
|
|
52
|
+
const closeExamplesModal = () => {
|
|
53
|
+
exampleModal.style.display = 'none'
|
|
54
|
+
}
|
|
55
|
+
form.addEventListener('submit', (e) => {
|
|
56
|
+
e.preventDefault()
|
|
57
|
+
drawImage()
|
|
58
|
+
})
|
|
59
|
+
async function face(imageSrc) {
|
|
60
|
+
return new Promise(async (resolve, reject) => {
|
|
61
|
+
await faceapi.nets.tinyFaceDetector.load('/assets/js/models'),
|
|
62
|
+
await faceapi.nets.faceLandmark68Net.load('/assets/js/models'),
|
|
63
|
+
await faceapi.nets.faceRecognitionNet.load('/assets/js/models'),
|
|
64
|
+
await faceapi.nets.faceExpressionNet.load('/assets/js/models')
|
|
65
|
+
|
|
66
|
+
const img = document.createElement('img')
|
|
67
|
+
img.src = imageSrc
|
|
68
|
+
img.onload = async () => {
|
|
69
|
+
const detections = await faceapi.detectSingleFace(
|
|
70
|
+
img,
|
|
71
|
+
new faceapi.TinyFaceDetectorOptions()
|
|
72
|
+
)
|
|
73
|
+
let faceDescriptions = await faceapi.detectSingleFace(
|
|
74
|
+
img,
|
|
75
|
+
new faceapi.TinyFaceDetectorOptions()
|
|
76
|
+
)
|
|
77
|
+
const canvas = document.createElement('canvas')
|
|
78
|
+
faceapi.matchDimensions(canvas, img)
|
|
79
|
+
faceDescriptions = faceapi.resizeResults(faceDescriptions, img)
|
|
80
|
+
faceapi.draw.drawDetections(canvas, faceDescriptions)
|
|
81
|
+
let value = extractFaceFromBox(img, detections.box, canvas)
|
|
82
|
+
resolve([value])
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
async function extractFaceFromBox(imageRef, box) {
|
|
87
|
+
const regionsToExtract = [
|
|
88
|
+
new faceapi.Rect(box.x, box.y, box.width, box.height),
|
|
89
|
+
]
|
|
90
|
+
let faceImages = await faceapi.extractFaces(imageRef, regionsToExtract)
|
|
91
|
+
if (faceImages.length === 0) {
|
|
92
|
+
return 'no face found'
|
|
93
|
+
} else {
|
|
94
|
+
return faceImages[0].toDataURL()
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const drawInputImage = (ctx, item, indexValue) => {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
let image = document.createElement('img')
|
|
100
|
+
image.src = files[indexValue]
|
|
101
|
+
image.onload = () => {
|
|
102
|
+
ctx.save()
|
|
103
|
+
image.width = Number(item.width)
|
|
104
|
+
image.height = Number(item.height)
|
|
105
|
+
if (item.filter) {
|
|
106
|
+
ctx.filter = item.filter
|
|
107
|
+
}
|
|
108
|
+
if (item.rotate) {
|
|
109
|
+
ctx.rotate((item.rotate * Math.PI) / 180)
|
|
110
|
+
}
|
|
111
|
+
let perspectiveKey = 'perspective' in item
|
|
112
|
+
if (!perspectiveKey) {
|
|
113
|
+
ctx.drawImage(
|
|
114
|
+
image,
|
|
115
|
+
Number(item.x),
|
|
116
|
+
Number(item.y),
|
|
117
|
+
image.width,
|
|
118
|
+
image.height
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
if (item.translate) {
|
|
122
|
+
ctx.translate(item.translate.x, item.translate.y)
|
|
123
|
+
}
|
|
124
|
+
if (perspectiveKey) {
|
|
125
|
+
let p = new Perspective(ctx, image)
|
|
126
|
+
p.draw([
|
|
127
|
+
[item.perspective.topLeft.x, item.perspective.topLeft.y],
|
|
128
|
+
[item.perspective.topRight.x, item.perspective.topRight.y],
|
|
129
|
+
[item.perspective.bottomRight.x, item.perspective.bottomRight.y],
|
|
130
|
+
[item.perspective.bottomLeft.x, item.perspective.bottomLeft.y],
|
|
131
|
+
])
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (item.skew) {
|
|
135
|
+
ctx.setTransform(1, item.skew.x, item.skew.y, 1, 0, 0)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
ctx.restore()
|
|
139
|
+
resolve()
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const drawImage = () => {
|
|
145
|
+
workspace.style.display = 'block'
|
|
146
|
+
document.querySelector('#upper-panel').style.display = 'none'
|
|
147
|
+
document.querySelector('#saving-data').style.display = 'flex'
|
|
148
|
+
let img = new Image()
|
|
149
|
+
img.src = featureData.effectImagePath
|
|
150
|
+
var canvas = document.createElement('canvas')
|
|
151
|
+
var ctx = canvas.getContext('2d')
|
|
152
|
+
img.onload = () => {
|
|
153
|
+
canvas.width = img.width
|
|
154
|
+
canvas.height = img.height
|
|
155
|
+
Promise.all(
|
|
156
|
+
featureData.elements.map((item, indexValue) => {
|
|
157
|
+
if (item.type === 'image') {
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
drawInputImage(ctx, item, indexValue, canvas).then(() => {
|
|
160
|
+
resolve()
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
).then(() => {
|
|
166
|
+
ctx.filter = 'none'
|
|
167
|
+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
|
|
168
|
+
featureData.elements.map((item, indexValue) => {
|
|
169
|
+
if (item.type === 'text') {
|
|
170
|
+
let myFont = new FontFace(item.font, `url(${item.fontPath})`)
|
|
171
|
+
myFont.load().then(function (font) {
|
|
172
|
+
ctx.save()
|
|
173
|
+
document.fonts.add(font)
|
|
174
|
+
let textValue = document.querySelector(`#${item.id}`).value
|
|
175
|
+
if (textValue.length > 10 && item.fontSizeOption1) {
|
|
176
|
+
item.fontSize = item.fontSizeOption1
|
|
177
|
+
}
|
|
178
|
+
if (textValue.length > 12 && item.fontSizeOption2) {
|
|
179
|
+
item.fontSize = item.fontSizeOption2
|
|
180
|
+
}
|
|
181
|
+
if (textValue.length > 15 && item.fontSizeOption3) {
|
|
182
|
+
item.fontSize = item.fontSizeOption3
|
|
183
|
+
}
|
|
184
|
+
if (textValue.length > 20 && item.fontSizeOption4) {
|
|
185
|
+
item.fontSize = item.fontSizeOption4
|
|
186
|
+
}
|
|
187
|
+
ctx.font = `${item.fontSize}px ${item.font}`
|
|
188
|
+
if (item.shadowColor) {
|
|
189
|
+
ctx.shadowColor = `${item.shadowColor}`
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (item.shadowOffsetX) {
|
|
193
|
+
ctx.shadowOffsetX = 3
|
|
194
|
+
}
|
|
195
|
+
if (item.shadowOffsetY) {
|
|
196
|
+
ctx.shadowOffsetY = 3
|
|
197
|
+
}
|
|
198
|
+
if (item.shadowBlur) {
|
|
199
|
+
ctx.shadowBlur = 2
|
|
200
|
+
}
|
|
201
|
+
if (item.rotate) {
|
|
202
|
+
ctx.rotate((item.rotate * Math.PI) / 180)
|
|
203
|
+
}
|
|
204
|
+
ctx.textAlign = 'center'
|
|
205
|
+
ctx.fillStyle = `${item.color}`
|
|
206
|
+
ctx.fillText(textValue, item.x, item.y)
|
|
207
|
+
ctx.restore()
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
if (item.type === 'rectangle') {
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
canvasPanel.innerHTML = ''
|
|
214
|
+
document.querySelector('#saving-data').style.display = 'none'
|
|
215
|
+
canvasPanel.appendChild(canvas)
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const cropImage = (result, id) => {
|
|
220
|
+
let image = new Image()
|
|
221
|
+
image.onload = () => {
|
|
222
|
+
let img = document.createElement('img')
|
|
223
|
+
img.src = result
|
|
224
|
+
img.id = 'image'
|
|
225
|
+
document.querySelector('.crop-image-modal-body').appendChild(img)
|
|
226
|
+
cropper = new Cropper(img, {
|
|
227
|
+
viewMode: 3,
|
|
228
|
+
ready() {
|
|
229
|
+
let find = featureData.elements.find((i) => i.id === id)
|
|
230
|
+
cropper.setAspectRatio(Number(find.width) / Number(find.height))
|
|
231
|
+
cropModal.style.display = 'flex'
|
|
232
|
+
this.cropper.crop()
|
|
233
|
+
},
|
|
234
|
+
crop(event) {
|
|
235
|
+
cropWidth = Math.round(event.detail.width)
|
|
236
|
+
cropHeight = Math.round(event.detail.height)
|
|
237
|
+
},
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
image.src = result
|
|
241
|
+
}
|
|
242
|
+
const updateCropper = (result, id) => {
|
|
243
|
+
cropper.destroy()
|
|
244
|
+
document.querySelector('.crop-image-modal-body').innerHTML = ''
|
|
245
|
+
cropImage(result, id)
|
|
246
|
+
}
|
|
247
|
+
document.querySelector('#crop').addEventListener('click', () => {
|
|
248
|
+
let cropperImg = cropper
|
|
249
|
+
.getCroppedCanvas({
|
|
250
|
+
width: cropWidth,
|
|
251
|
+
height: cropHeight,
|
|
252
|
+
})
|
|
253
|
+
.toDataURL()
|
|
254
|
+
face(cropperImg).then(([value]) => {
|
|
255
|
+
value.then((result) => {
|
|
256
|
+
files[index - 1] = result
|
|
257
|
+
document.querySelector(`#image-pre-${index}`).src = result
|
|
258
|
+
document.querySelector(`#image-pre-${index}`).style.display = 'block'
|
|
259
|
+
document.querySelector(`#cam-${index}`).style.display = 'none'
|
|
260
|
+
cropModal.style.display = 'none'
|
|
261
|
+
})
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
const openExamplesModal = () => {
|
|
265
|
+
exampleModal.style.display = 'flex'
|
|
266
|
+
}
|
|
267
|
+
let inputFile = ''
|
|
268
|
+
const handleFile = (file) => {
|
|
269
|
+
cropModal.style.display = 'flex'
|
|
270
|
+
document.querySelector('#file-loader').style.display = 'flex'
|
|
271
|
+
document.querySelector('.file-input').style.display = 'none'
|
|
272
|
+
inputFile = file
|
|
273
|
+
if (file) {
|
|
274
|
+
const reader = new FileReader()
|
|
275
|
+
reader.onload = (e) => {
|
|
276
|
+
if (e.target.result) {
|
|
277
|
+
cropImage(e.target.result)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
reader.readAsDataURL(file)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const showLoading = () => {
|
|
284
|
+
document.querySelector('#file-loader').style.display = 'flex'
|
|
285
|
+
document.querySelector('.file-input').style.display = 'none'
|
|
286
|
+
}
|
|
287
|
+
const stopLoading = () => {
|
|
288
|
+
fileDropBox.style.display = 'none'
|
|
289
|
+
}
|
|
290
|
+
download.addEventListener('click', () => {
|
|
291
|
+
let canvas = document.querySelector('canvas')
|
|
292
|
+
let url = canvas.toDataURL(`image/png`)
|
|
293
|
+
let a = document.createElement('a')
|
|
294
|
+
a.href = url
|
|
295
|
+
a.download = `safeimagekit-photo-effect-image.png`
|
|
296
|
+
document.body.appendChild(a)
|
|
297
|
+
a.click()
|
|
298
|
+
if (lang === 'en') {
|
|
299
|
+
window.location.href = `/download?tool=${pageTool}`
|
|
300
|
+
} else {
|
|
301
|
+
window.location.href = `/${lang}/download?tool=${pageTool}`
|
|
302
|
+
}
|
|
303
|
+
})
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
let script = document.currentScript;
|
|
2
|
+
const params = new URLSearchParams(window.location.search);
|
|
3
|
+
let type = params.get("fileName");
|
|
4
|
+
let jsonFileName = atob(type);
|
|
5
|
+
let folderName = script.dataset.foldername;
|
|
6
|
+
let fileName = jsonFileName;
|
|
7
|
+
let lang = script.dataset.lang;
|
|
8
|
+
let headingDiv = document.querySelector("#heading-div");
|
|
9
|
+
let feature_h1 = document.createElement("h1");
|
|
10
|
+
let feature_h2 = document.createElement("h2");
|
|
11
|
+
feature_h1.setAttribute("class", "feature-h1");
|
|
12
|
+
feature_h2.setAttribute("class", "feature-h2");
|
|
13
|
+
headingDiv.appendChild(feature_h1);
|
|
14
|
+
headingDiv.appendChild(feature_h2);
|
|
15
|
+
|
|
16
|
+
let feature_img = document.querySelector(".features-img");
|
|
17
|
+
|
|
18
|
+
const getSeodata = async () => {
|
|
19
|
+
let URL = "/data" + "/" + folderName + "/" + lang + "/" + fileName + ".json";
|
|
20
|
+
const data = await fetch(URL);
|
|
21
|
+
const seoData = await data.json();
|
|
22
|
+
|
|
23
|
+
feature_h1.innerHTML = seoData.H1;
|
|
24
|
+
feature_h2.innerHTML = seoData.H2;
|
|
25
|
+
|
|
26
|
+
document.head
|
|
27
|
+
.querySelector('meta[property="og:title"]')
|
|
28
|
+
.setAttribute("content", seoData.TITLE);
|
|
29
|
+
document.head
|
|
30
|
+
.querySelector('meta[name="description"]')
|
|
31
|
+
.setAttribute("content", seoData.META);
|
|
32
|
+
document.head
|
|
33
|
+
.querySelector('meta[name="twitter:title"]')
|
|
34
|
+
.setAttribute("content", seoData.TITLE);
|
|
35
|
+
document.head
|
|
36
|
+
.querySelector('meta[name="twitter:description"]')
|
|
37
|
+
.setAttribute("content", seoData.META);
|
|
38
|
+
|
|
39
|
+
if (seoData.img) {
|
|
40
|
+
feature_img.src = seoData.img;
|
|
41
|
+
feature_img.setAttribute("alt", seoData.imgalt);
|
|
42
|
+
feature_img.style.width = seoData.imgwidth;
|
|
43
|
+
feature_img.style.height = seoData.imgheight;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
document.title = seoData.TITLE;
|
|
47
|
+
};
|
|
48
|
+
getSeodata();
|
data/assets/js/frame.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
---
|
|
2
|
+
---
|
|
3
|
+
|
|
4
|
+
const getScript = document.currentScript
|
|
5
|
+
const pageTool = getScript.dataset.tool
|
|
6
|
+
const downloadName = "{{site.downloadName}}"
|
|
7
|
+
const lang = getScript.dataset.lang
|
|
8
|
+
const inputBox = document.querySelector('#Inputbox')
|
|
9
|
+
const fileDropBox = document.querySelector('.custom-box')
|
|
10
|
+
const cropModal = document.querySelector('.crop-image-modal-container')
|
|
11
|
+
const exampleModal = document.querySelector('.example-images-modal-container')
|
|
12
|
+
const workspace = document.getElementById('workspace')
|
|
13
|
+
const canvasPanel = document.getElementById('canvas-panel')
|
|
14
|
+
const download = document.querySelector('#download-button')
|
|
15
|
+
const form = document.querySelector('#effect-form')
|
|
16
|
+
let files = []
|
|
17
|
+
let cropWidth = null
|
|
18
|
+
let cropHeight = null
|
|
19
|
+
let cropper = null
|
|
20
|
+
let cropInputWidth = null
|
|
21
|
+
let index = 0
|
|
22
|
+
let cropInputHeight = null
|
|
23
|
+
let image = null
|
|
24
|
+
const showLoader = () => {
|
|
25
|
+
showLoading()
|
|
26
|
+
}
|
|
27
|
+
const closeLoader = () => { }
|
|
28
|
+
const clickInput = (e) => {
|
|
29
|
+
console.log(`#file-${e.dataset.index}`)
|
|
30
|
+
document.querySelector(`#file-${e.dataset.index}`).click()
|
|
31
|
+
}
|
|
32
|
+
let featureData = null
|
|
33
|
+
fetch('/assets/js/photo-effects.json')
|
|
34
|
+
.then((response) => response.json())
|
|
35
|
+
.then((data) => {
|
|
36
|
+
featureData = data.find((i) => i.name === form.dataset.featureName)
|
|
37
|
+
console.log(featureData)
|
|
38
|
+
})
|
|
39
|
+
const fileOnChange = (e) => {
|
|
40
|
+
index = Number(e.dataset.index)
|
|
41
|
+
let reader = new FileReader()
|
|
42
|
+
reader.onload = (event) => {
|
|
43
|
+
cropModal.style.display = 'flex'
|
|
44
|
+
if (cropper === null) {
|
|
45
|
+
cropImage(event.target.result, e.id)
|
|
46
|
+
} else {
|
|
47
|
+
updateCropper(event.target.result, e.id)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
reader.readAsDataURL(e.files[0])
|
|
51
|
+
}
|
|
52
|
+
const closeModal = () => {
|
|
53
|
+
cropModal.style.display = 'none'
|
|
54
|
+
document.body.style.overflow = "auto"
|
|
55
|
+
}
|
|
56
|
+
const closeExamplesModal = () => {
|
|
57
|
+
exampleModal.style.display = 'none'
|
|
58
|
+
}
|
|
59
|
+
form.addEventListener('submit', (e) => {
|
|
60
|
+
e.preventDefault()
|
|
61
|
+
drawImage()
|
|
62
|
+
})
|
|
63
|
+
const drawInputImage = (ctx, item, indexValue) => {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
let image = document.createElement('img')
|
|
66
|
+
image.src = files[indexValue]
|
|
67
|
+
image.onload = () => {
|
|
68
|
+
ctx.save()
|
|
69
|
+
image.width = Number(item.width)
|
|
70
|
+
image.height = Number(item.height)
|
|
71
|
+
if (item.filter) {
|
|
72
|
+
ctx.filter = item.filter
|
|
73
|
+
}
|
|
74
|
+
if (item.rotate) {
|
|
75
|
+
ctx.rotate((item.rotate * Math.PI) / 180)
|
|
76
|
+
}
|
|
77
|
+
let perspectiveKey = 'perspective' in item
|
|
78
|
+
if (!perspectiveKey) {
|
|
79
|
+
ctx.drawImage(
|
|
80
|
+
image,
|
|
81
|
+
Number(item.x),
|
|
82
|
+
Number(item.y),
|
|
83
|
+
image.width,
|
|
84
|
+
image.height
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
if (item.translate) {
|
|
88
|
+
ctx.translate(item.translate.x, item.translate.y)
|
|
89
|
+
}
|
|
90
|
+
if (perspectiveKey) {
|
|
91
|
+
let p = new Perspective(ctx, image)
|
|
92
|
+
p.draw([
|
|
93
|
+
[item.perspective.topLeft.x, item.perspective.topLeft.y],
|
|
94
|
+
[item.perspective.topRight.x, item.perspective.topRight.y],
|
|
95
|
+
[item.perspective.bottomRight.x, item.perspective.bottomRight.y],
|
|
96
|
+
[item.perspective.bottomLeft.x, item.perspective.bottomLeft.y],
|
|
97
|
+
])
|
|
98
|
+
}
|
|
99
|
+
if (item.skew) {
|
|
100
|
+
ctx.setTransform(1, item.skew.x, item.skew.y, 1, 0, 0)
|
|
101
|
+
}
|
|
102
|
+
ctx.restore()
|
|
103
|
+
resolve()
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
const drawImage = () => {
|
|
108
|
+
workspace.style.display = 'block'
|
|
109
|
+
document.querySelector('#upper-panel').style.display = 'none'
|
|
110
|
+
document.querySelector('#saving-data').style.display = 'flex'
|
|
111
|
+
let img = new Image()
|
|
112
|
+
img.src = featureData.effectImagePath
|
|
113
|
+
var canvas = document.createElement('canvas')
|
|
114
|
+
var ctx = canvas.getContext('2d')
|
|
115
|
+
img.onload = () => {
|
|
116
|
+
canvas.width = img.width
|
|
117
|
+
canvas.height = img.height
|
|
118
|
+
Promise.all(
|
|
119
|
+
featureData.elements.map((item, indexValue) => {
|
|
120
|
+
if (item.type === 'image') {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
drawInputImage(ctx, item, indexValue, canvas).then(() => {
|
|
123
|
+
resolve()
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
).then(() => {
|
|
129
|
+
ctx.filter = 'none'
|
|
130
|
+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
|
|
131
|
+
featureData.elements.map((item, indexValue) => {
|
|
132
|
+
if (item.type === 'text') {
|
|
133
|
+
let myFont = new FontFace(item.font, `url(${item.fontPath})`)
|
|
134
|
+
myFont.load().then(function (font) {
|
|
135
|
+
ctx.save()
|
|
136
|
+
document.fonts.add(font)
|
|
137
|
+
let textValue = document.querySelector(`#${item.id}`).value
|
|
138
|
+
if (textValue.length > 10 && item.fontSizeOption1) {
|
|
139
|
+
item.fontSize = item.fontSizeOption1
|
|
140
|
+
}
|
|
141
|
+
if (textValue.length > 12 && item.fontSizeOption2) {
|
|
142
|
+
item.fontSize = item.fontSizeOption2
|
|
143
|
+
}
|
|
144
|
+
if (textValue.length > 15 && item.fontSizeOption3) {
|
|
145
|
+
item.fontSize = item.fontSizeOption3
|
|
146
|
+
}
|
|
147
|
+
if (textValue.length > 20 && item.fontSizeOption4) {
|
|
148
|
+
item.fontSize = item.fontSizeOption4
|
|
149
|
+
}
|
|
150
|
+
ctx.font = `${item.fontSize}px ${item.font}`
|
|
151
|
+
if (item.shadowColor) {
|
|
152
|
+
ctx.shadowColor = `${item.shadowColor}`
|
|
153
|
+
}
|
|
154
|
+
if (item.shadowOffsetX) {
|
|
155
|
+
ctx.shadowOffsetX = 3
|
|
156
|
+
}
|
|
157
|
+
if (item.shadowOffsetY) {
|
|
158
|
+
ctx.shadowOffsetY = 3
|
|
159
|
+
}
|
|
160
|
+
if (item.shadowBlur) {
|
|
161
|
+
ctx.shadowBlur = 2
|
|
162
|
+
}
|
|
163
|
+
if (item.rotate) {
|
|
164
|
+
ctx.rotate((item.rotate * Math.PI) / 180)
|
|
165
|
+
}
|
|
166
|
+
ctx.textAlign = 'center'
|
|
167
|
+
ctx.fillStyle = `${item.color}`
|
|
168
|
+
ctx.fillText(textValue, item.x, item.y)
|
|
169
|
+
ctx.restore()
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
if (item.type === 'rectangle') {
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
canvasPanel.innerHTML = ''
|
|
176
|
+
document.querySelector('#saving-data').style.display = 'none'
|
|
177
|
+
canvasPanel.appendChild(canvas)
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const cropImage = (result, id) => {
|
|
182
|
+
document.body.style.overflow = "hidden"
|
|
183
|
+
let image = new Image()
|
|
184
|
+
image.onload = () => {
|
|
185
|
+
let img = document.createElement('img')
|
|
186
|
+
img.src = result
|
|
187
|
+
img.id = 'image'
|
|
188
|
+
document.querySelector('.crop-image-modal-body').appendChild(img)
|
|
189
|
+
cropper = new Cropper(img, {
|
|
190
|
+
viewMode: 3,
|
|
191
|
+
ready() {
|
|
192
|
+
let find = featureData.elements.find((i) => i.id === id)
|
|
193
|
+
console.log(find)
|
|
194
|
+
cropper.setAspectRatio(Number(find.width) / Number(find.height))
|
|
195
|
+
cropModal.style.display = 'flex'
|
|
196
|
+
this.cropper.crop()
|
|
197
|
+
},
|
|
198
|
+
crop(event) {
|
|
199
|
+
cropWidth = Math.round(event.detail.width)
|
|
200
|
+
cropHeight = Math.round(event.detail.height)
|
|
201
|
+
},
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
image.src = result
|
|
205
|
+
}
|
|
206
|
+
const updateCropper = (result, id) => {
|
|
207
|
+
cropper.destroy()
|
|
208
|
+
document.querySelector('.crop-image-modal-body').innerHTML = ''
|
|
209
|
+
cropImage(result, id)
|
|
210
|
+
}
|
|
211
|
+
document.querySelector('#crop').addEventListener('click', () => {
|
|
212
|
+
let cropperImg = cropper
|
|
213
|
+
.getCroppedCanvas({
|
|
214
|
+
width: cropWidth,
|
|
215
|
+
height: cropHeight,
|
|
216
|
+
})
|
|
217
|
+
.toDataURL()
|
|
218
|
+
files[index - 1] = cropperImg
|
|
219
|
+
document.querySelector(`#image-pre-${index}`).src = cropperImg
|
|
220
|
+
document.querySelector(`#image-pre-${index}`).style.display = 'block'
|
|
221
|
+
document.querySelector(`#cam-${index}`).style.display = 'none'
|
|
222
|
+
cropModal.style.display = 'none'
|
|
223
|
+
document.body.style.overflow = "auto"
|
|
224
|
+
})
|
|
225
|
+
const openExamplesModal = () => {
|
|
226
|
+
exampleModal.style.display = 'flex'
|
|
227
|
+
}
|
|
228
|
+
let inputFile = ''
|
|
229
|
+
const handleFile = (file) => {
|
|
230
|
+
cropModal.style.display = 'flex'
|
|
231
|
+
document.querySelector('#file-loader').style.display = 'flex'
|
|
232
|
+
document.querySelector('.file-input').style.display = 'none'
|
|
233
|
+
inputFile = file
|
|
234
|
+
if (file) {
|
|
235
|
+
const reader = new FileReader()
|
|
236
|
+
reader.onload = (e) => {
|
|
237
|
+
if (e.target.result) {
|
|
238
|
+
cropImage(e.target.result)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
reader.readAsDataURL(file)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const showLoading = () => {
|
|
245
|
+
document.querySelector('#file-loader').style.display = 'flex'
|
|
246
|
+
document.querySelector('.file-input').style.display = 'none'
|
|
247
|
+
}
|
|
248
|
+
const stopLoading = () => {
|
|
249
|
+
fileDropBox.style.display = 'none'
|
|
250
|
+
}
|
|
251
|
+
download.addEventListener('click', () => {
|
|
252
|
+
let canvas = document.querySelector('canvas')
|
|
253
|
+
let url = canvas.toDataURL(`image/png`)
|
|
254
|
+
let a = document.createElement('a')
|
|
255
|
+
a.href = url
|
|
256
|
+
a.download = `${downloadName}-image.png`
|
|
257
|
+
document.body.appendChild(a)
|
|
258
|
+
a.click()
|
|
259
|
+
if (lang === 'en') {
|
|
260
|
+
window.location.href = `/download?tool=${pageTool}`
|
|
261
|
+
} else {
|
|
262
|
+
window.location.href = `/${lang}/download?tool=${pageTool}`
|
|
263
|
+
}
|
|
264
|
+
})
|