JSFiddle - React, Tailwind, and code Playground

HTML

<img id="image1">
<img id="image2">

JavaScript

function svgUri(text) {
  let svg = `
    <svg width="320" height="240" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="0" width="320" height="240" style="fill: #ddd; stroke: #666; stroke-width: 4;" />
      <text x="50%" y="50%" font-size="24" text-anchor="middle" alignment-baseline="middle" fill="#666">
        ${text}
      </text>
    </svg>
  `
  return 'data:image/svg+xml;charset=utf8,' + window.escape(svg)
}

window.image1.src = svgUri('Example 1')
window.image2.src = svgUri('Example 2')