Skip to content Skip to sidebar Skip to footer

Create An Arc Text Using Canvas

Is there any way to create an arc text using canvas? I followed the answer our here: How to make rooftext effect and valley text effect in HTML5 (or Fabric.js) Best thing I got wa

Solution 1:

body {
  background-color: #333;
  font-family: 'Luckiest Guy', cursive;
  font-size: 35px;
}

path {
  fill: transparent;
}

text {
  fill: #FF9800;
}
<svgviewBox="0 0 425 300"><pathid="curve"d="M6,150C49.63,93,105.79,36.65,156.2,47.55,207.89,58.74,213,131.91,264,150c40.67,14.43,108.57-6.91,229-145" /><textx="25"><textPathxlink:href="#curve">
      Dangerous Curves Ahead
    </textPath></text></svg>

Solution 2:

Try this for making text to apper in arc.

functiondrawTextAlongArc(context, str, centerX, centerY, radius, angle) {
        var len = str.length, s;
        context.save();
        context.translate(centerX, centerY);
        context.rotate(-1 * angle / 2);
        context.rotate(-1 * (angle / len) / 2);
        for(var n = 0; n < len; n++) {
          context.rotate(angle / len);
          context.save();
          context.translate(0, -1 * radius);
          s = str[n];
          context.fillText(s, 0, 0);
          context.restore();
        }
        context.restore();
      }
      var canvas = document.getElementById('myCanvas'), 
        context = canvas.getContext('2d'),
        centerX = canvas.width / 2,
        centerY = canvas.height - 30,
        angle = Math.PI * 0.8,
        radius = 150;
      
      context.font = '30pt Calibri';
      context.textAlign = 'center';
      context.fillStyle = 'red';
      context.strokeStyle = 'blue';
      context.lineWidth = 4;
      drawTextAlongArc(context, 'Arc Canvas Text', centerX, centerY, radius, angle);

      // draw circle underneath text
      context.arc(centerX, centerY, radius - 10, 0, 2 * Math.PI, false);
      context.stroke();
#canvas{
  display:block;
  margin:0 auto;
}
<canvasid="myCanvas"width="578"height="250"></canvas>

Post a Comment for "Create An Arc Text Using Canvas"