MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / addTextElementToImageNode

Function addTextElementToImageNode

chrome-extension/src/content.js:94–121  ·  view source on GitHub ↗

* Moves the provided imgNode into a container div, and adds a text div as a * peer. Styles the container div and text div to place the text * on top of the image. * @param {HTMLElement} imgNode Which image node to write content on. * @param {string} textContent What text to write on the image.

(imgNode, textContent)

Source from the content-addressed store, hash-verified

92 * @param {string} textContent What text to write on the image.
93 */
94function addTextElementToImageNode(imgNode, textContent) {
95 const originalParent = imgNode.parentElement;
96 const container = document.createElement('div');
97 container.style.position = 'relative';
98 container.style.textAlign = 'center';
99 container.style.color = 'white';
100 const text = document.createElement('div');
101 text.className = 'tfjs_mobilenet_extension_text';
102 text.style.position = 'absolute';
103 text.style.top = '50%';
104 text.style.left = '50%';
105 text.style.transform = 'translate(-50%, -50%)';
106 text.style.fontSize = '34px';
107 text.style.fontFamily = 'Google Sans,sans-serif';
108 text.style.fontWeight = '700';
109 text.style.color = 'white';
110 text.style.lineHeight = '1em';
111 text.style['-webkit-text-fill-color'] = 'white';
112 text.style['-webkit-text-stroke-width'] = '1px';
113 text.style['-webkit-text-stroke-color'] = 'black';
114 // Add the containerNode as a peer to the image, right next to the image.
115 originalParent.insertBefore(container, imgNode);
116 // Move the imageNode to inside the containerNode;
117 container.appendChild(imgNode);
118 // Add the text node right after the image node;
119 container.appendChild(text);
120 text.textContent = textContent;
121}
122
123// Add a listener to hear from the content.js page when the image is through
124// processing. The message should contin an action, a url, and predictions (the

Callers 1

content.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected