Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <img id="picture" src="" />
<canvas id="card" />




                const OCR_API = '';
const img = document.getElementById('picture');
const canvas = document.getElementById("card");
const ctx = canvas.getContext("2d");
const imgWidth = img.width;
const imgHeight = img.height;
const scaleFactor = imgWidth / 1201;

async function imageToText (imageUrl) {
  const res = await fetch(`${OCR_API}&url=${encodeURIComponent(imageUrl)}`, {
    method: 'GET',
  const json = await res.json();
  const lines = json['ParsedResults'][0]['TextOverlay']['Lines'];
  return lines;

async function replaceText(target, replacement, lines) {
  const targetLines = lines.filter(line => line.LineText.includes(target));

  targetLines.forEach(line => {
    line.Words.forEach(word => {
      const index = target.indexOf(word.WordText);

      if (index != -1) {
        const replaceWith = replacement[index];
        const targetWord = target[index];
        ctx.fillStyle = '#00ff00';
        ctx.fillRect(word.Left, word.Top, word.Width, word.Height);
        ctx.fillStyle = 'white';
        ctx.fillText(replaceWith, word.Left + 2, word.Top + (word.Height / 2));

function loadImageIntoCanvas() {
  canvas.width = imgWidth;
  canvas.height = imgHeight;
  ctx.drawImage(img, 0, 0, 1201 * scaleFactor, 1800 * scaleFactor);
  ctx.font = 'bold 52px system-ui';
  ctx.textBaseline = 'middle';
  // call OCR API 返回目標文字位置
  imageToText(img.src).then(lines => {
    replaceText('安倍', '習總', lines); // replace 標文字
    replaceText('安培', '習總', lines);