MCPcopy
hub / github.com/hoothin/UserScripts / icon2Base64

Function icon2Base64

Picviewer CE+/Picviewer CE+.user.js:12250–12265  ·  view source on GitHub ↗
(icon, content, iconStyle)

Source from the content-addressed store, hash-verified

12248 }
12249 var formatDict = new Map();
12250 function icon2Base64(icon, content, iconStyle) {
12251 if (!content || !canvas) return false;
12252 let size = Math.min((icon.clientWidth || icon.offsetWidth), (icon.clientHeight || icon.offsetHeight));
12253 if (!size) return false;
12254 canvas.width = size;
12255 canvas.height = size;
12256 var ctx = canvas.getContext("2d");
12257 ctx.clearRect(0, 0, canvas.width, canvas.height);
12258 ctx.font = iconStyle.font || (iconStyle.fontSize + " " + iconStyle.fontFamily);
12259 ctx.strokeStyle = iconStyle.color || "black";
12260 ctx.fillStyle = iconStyle.color || "black";
12261 ctx.textBaseline = "top";
12262 let metrics = ctx.measureText(content);
12263 ctx.fillText(content, (canvas.width - metrics.width) / 2, (canvas.height - parseInt(iconStyle.fontSize)) / 2);
12264 return canvas.toDataURL("image/png");
12265 }
12266
12267 function getRightSaveName(url, name, type, _ext) {
12268 /*

Callers 1

anylizeEleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected