mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-02 22:17:03 +03:00
Added advanced PluginPropertyType::SELECT for improved Avatars plugin
This commit is contained in:
parent
2f4e17da51
commit
c56cc7be73
7 changed files with 57 additions and 59 deletions
|
|
@ -15,14 +15,15 @@ window.identiconSvg = (hash, txt) => {
|
|||
l,
|
||||
l + h % 1 * s,
|
||||
l + s
|
||||
];
|
||||
],
|
||||
m = txt ? 128 : 255,
|
||||
color = 'rgb(' + [
|
||||
v[ ~~h % 6 ] * m, // red
|
||||
v[ (h | 16) % 6 ] * m, // green
|
||||
v[ (h | 8) % 6 ] * m // blue
|
||||
].map(Math.round).join(',') + ')';
|
||||
|
||||
if (txt) {
|
||||
const color = 'rgb(' + [
|
||||
v[ ~~h % 6 ] * 255 / 2, // red
|
||||
v[ (h | 16) % 6 ] * 255 / 2, // green
|
||||
v[ (h | 8) % 6 ] * 255 / 2 // blue
|
||||
].map(Math.round).join(',') + ')';
|
||||
txt = `<svg xmlns="http://www.w3.org/2000/svg" width="${size}px" height="${size}px" viewBox="0 0 ${size} ${size}" version="1.1">
|
||||
<circle fill="${color}" width="${size}" height="${size}" cx="${size/2}" cy="${size/2}" r="${size/2}"/>
|
||||
<text x="${size}%" y="${size}%" style="color:#FFF" alignment-baseline="middle" text-anchor="middle"
|
||||
|
|
@ -30,18 +31,12 @@ window.identiconSvg = (hash, txt) => {
|
|||
dy=".1em" dominant-baseline="middle" fill="#FFF">${txt}</text>
|
||||
</svg>`;
|
||||
} else {
|
||||
const color = 'rgb(' + [
|
||||
v[ ~~h % 6 ] * 255, // red
|
||||
v[ (h | 16) % 6 ] * 255, // green
|
||||
v[ (h | 8) % 6 ] * 255 // blue
|
||||
].map(Math.round).join(',') + ')',
|
||||
cell = Math.floor((size - ((Math.floor(size * margin)) * 2)) / 5),
|
||||
const cell = Math.floor((size - ((Math.floor(size * margin)) * 2)) / 5),
|
||||
imargin = Math.floor((size - cell * 5) / 2),
|
||||
rectangles = [],
|
||||
add = (x, y) => rectangles.push("<rect x='" + (x * cell + imargin)
|
||||
+ "' y='" + (y * cell + imargin)
|
||||
+ "' width='" + cell + "' height='" + cell + "'/>");
|
||||
|
||||
// the first 15 characters of the hash control the pixels (even/odd)
|
||||
// they are drawn down the middle first, then mirrored outwards
|
||||
for (let i = 0; i < 15; ++i) {
|
||||
|
|
@ -51,7 +46,7 @@ window.identiconSvg = (hash, txt) => {
|
|||
} else if (i < 10) {
|
||||
add(1, (i - 5));
|
||||
add(3, (i - 5));
|
||||
} else if (i < 15) {
|
||||
} else {
|
||||
add(0, (i - 10));
|
||||
add(4, (i - 10));
|
||||
}
|
||||
|
|
@ -61,9 +56,7 @@ window.identiconSvg = (hash, txt) => {
|
|||
+ rectangles.join('')
|
||||
+ "</g>";
|
||||
}
|
||||
return 'data:image/svg+xml;base64,' + btoa(
|
||||
"<svg xmlns='http://www.w3.org/2000/svg' width='" + size + "' height='" + size + "'>" + txt + "</svg>"
|
||||
);
|
||||
return "<svg xmlns='http://www.w3.org/2000/svg' width='" + size + "' height='" + size + "'>" + txt + "</svg>";
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue