PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / v3 / src / assets / js / common / image.js
ameliabooking / v3 / src / assets / js / common Last commit date
appointments.js 1 year ago attendees.js 1 year ago colorManipulation.js 3 years ago customer.js 1 year ago date.js 1 year ago defaultCustomize.js 1 year ago employee.js 1 year ago events.js 1 year ago formFieldsTemplates.js 3 years ago formatting.js 1 year ago helper.js 1 year ago image.js 1 year ago integrationApple.js 1 year ago integrationGoogle.js 1 year ago integrationOutlook.js 1 year ago integrationStripe.js 1 year ago integrationZoom.js 1 year ago licence.js 2 years ago objectAndArrayManipulation.js 3 years ago pricing.js 1 year ago recurring.js 1 year ago responsive.js 1 year ago scrollElements.js 4 years ago settings.js 1 year ago translationsElementPlus.js 1 year ago
image.js
78 lines
1 let usedColors = []
2 let colors = [
3 '1788FB',
4 '4BBEC6',
5 'FBC22D',
6 'FA3C52',
7 'D696B8',
8 '689BCA',
9 '26CC2B',
10 'FD7E35',
11 'E38587',
12 '774DFB',
13 '31CDF3',
14 '6AB76C',
15 'FD5FA1',
16 'A697C5'
17 ]
18
19 function usePictureLoad (baseUrls, entity, isPerson) {
20 if (entity !== null) {
21 let name = isPerson === true ? entity.firstName + ' ' + entity.lastName : entity.name
22 if (typeof name !== 'undefined') {
23 entity.pictureThumbPath = entity.pictureThumbPath || imageFromText(baseUrls, name)
24 return entity.pictureThumbPath
25 }
26 }
27 }
28
29 function getNameInitials (name) {
30 return name.split(' ').map((s) => s.charAt(0)).join('').toUpperCase().substring(0, 3).replace(/[^\w\s]/g, '')
31 }
32
33 function imageFromText (baseUrls, name, entity = {}, error = false) {
34 let initials = getNameInitials(name)
35 let colorIndex = Math.floor(Math.random() * colors.length)
36 let colorHex = colors[colorIndex]
37 usedColors.push(colors[colorIndex])
38 colors.splice(colorIndex, 1)
39 if (colors.length === 0) {
40 colors = usedColors
41 usedColors = []
42 }
43 if (error) {
44 if (entity.firstName) {
45 return baseUrls.wpAmeliaPluginURL + 'public/img/default-employee.svg'
46 }
47 if (entity.latitude) {
48 return baseUrls.wpAmeliaPluginURL + 'public/img/default-location.svg'
49 }
50 return baseUrls.wpAmeliaPluginURL + 'public/img/default-service.svg'
51 }
52
53 // Make canvas
54 const canvas = document.createElement('canvas');
55 canvas.width = 100;
56 canvas.height = 100;
57 const ctx = canvas.getContext('2d');
58
59 // Draw background color
60 ctx.fillStyle = `#${colorHex}` // Background color
61 ctx.fillRect(0, 0, canvas.width, canvas.height);
62
63 // Draw initials text
64 ctx.font = '40px Arial';
65 ctx.fillStyle = '#ffffff'; // Text color
66 ctx.textAlign = 'center';
67 ctx.textBaseline = 'middle';
68 ctx.fillText(initials, canvas.width / 2, canvas.height / 2);
69
70 // Convert canvas to data URL (as image source)
71 return canvas.toDataURL('image/png');
72 }
73
74 export {
75 usePictureLoad,
76 getNameInitials
77 }
78