forked from open-webui/open-webui
refac: move generateInitialsImage function to utils
This commit is contained in:
parent
4195af4942
commit
0c43897f3d
3 changed files with 25 additions and 24 deletions
|
@ -96,6 +96,28 @@ export const getGravatarURL = (email) => {
|
|||
return `https://www.gravatar.com/avatar/${hash}`;
|
||||
};
|
||||
|
||||
export const generateInitialsImage = (name) => {
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
canvas.width = 100;
|
||||
canvas.height = 100;
|
||||
|
||||
ctx.fillStyle = '#F39C12';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
ctx.fillStyle = '#FFFFFF';
|
||||
ctx.font = '40px Helvetica';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
const initials = name
|
||||
.split(' ')
|
||||
.map((word) => word[0])
|
||||
.join('');
|
||||
ctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2);
|
||||
|
||||
return canvas.toDataURL();
|
||||
};
|
||||
|
||||
export const copyToClipboard = (text) => {
|
||||
if (!navigator.clipboard) {
|
||||
const textArea = document.createElement('textarea');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue