Client: PortalSettings: WhiteLabel: fix use text as logo

This commit is contained in:
Viktor Fomin 2022-11-23 08:56:08 +05:00
parent 76d2c6ed28
commit b8715c153b
2 changed files with 28 additions and 8 deletions

View File

@ -54,15 +54,28 @@ const WhiteLabel = (props) => {
};
const onUseTextAsLogo = () => {
let newLogos = [];
let newLogos = logoUrlsWhiteLabel;
for (let i = 0; i < logoUrlsWhiteLabel.length; i++) {
const width = logoUrlsWhiteLabel[i].width / 2;
const height = logoUrlsWhiteLabel[i].height / 2;
const width = logoUrlsWhiteLabel[i].size.width / 2;
const height = logoUrlsWhiteLabel[i].size.height / 2;
const options = getLogoOptions(i, logoTextWhiteLabel);
console.log(i, logoUrlsWhiteLabel[i]);
const logo = generateLogo(width, height, options.text, options.fontSize);
newLogos.push(logo);
const logoLight = generateLogo(
width,
height,
options.text,
options.fontSize
);
const logoDark = generateLogo(
width,
height,
options.text,
options.fontSize,
"#fff"
);
newLogos[i].path.light = logoLight;
newLogos[i].path.dark = logoDark;
}
setLogoUrlsWhiteLabel(newLogos);
};

View File

@ -1,15 +1,22 @@
export const generateLogo = (width, height, text, fontSize = 18) => {
export const generateLogo = (
width,
height,
text,
fontSize = 18,
fontColor = "#000"
) => {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "transparent";
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = "#000";
ctx.fillStyle = fontColor;
ctx.textAlign = "start";
ctx.textBaseline = "top";
ctx.font = `${fontSize}px Arial`;
ctx.fillText(text, 0, 0);
return canvas.toDataURL();
};