Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:52:38+00:00 2026-05-27T22:52:38+00:00

The following draws text into a canvas image, into a top line and a

  • 0

The following draws text into a canvas image, into a top line and a bottom line. The issue is that stroketext() make weird polygon shapes come out of the text. Both filltext() and stroketext() need to be use so that the text can be white with a black border, which will be visible on any image irrespective of its background colour. Is there any way to remove the polygons?

drawText = function(context, pos, text) {
    var fontSize = 100;
    while(1) {
        context.font = "bold " + fontSize + "px Arial";
        if( (context.measureText(text).width < (width-15)) && (fontSize < height/10) ) {
            break;
        }
        fontSize-=2;
    }

    var y;
    if(pos == "top")
        y = fontSize + 15;
    else if(pos == "bottom") {
        y = height - 15;
    }

    context.strokeText(text, width/2, y);
    context.fillText(text, width/2, y); 
}

updateList = function(doc, where) {
    if(where == "top")
        $("#list").prepend(makeCanvas(doc));
    else {
        $("#list").append(makeCanvas(doc));
    }
    var canvas = document.getElementById(doc._id);
    var context = canvas.getContext("2d");
    context.textAlign = "center";
    context.fillStyle = "#fff";
    context.strokeStyle = "#000";
    context.lineWidth = 6;

    var img = new Image();
    img.src = getTemplateLink(doc.name);
    img.onload = function() {
        context.drawImage(img, 0, 0, canvas.width, canvas.height);
        drawText(context, "top", doc.text.line1);
        drawText(context, "bottom", doc.text.line2);
    };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:52:39+00:00Added an answer on May 27, 2026 at 10:52 pm

    Calling only fillText() doesn’t show the “weird polygon shapes” but adding a call to strokeText() does? Are the characters in the text string all present in the “Arial _px Bold” font – i.e., are there embedded newline or tab or other characters for which Arial would normally show a box? Obviously I haven’t tried your code, but these are questions I came up with to perhaps help a bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to remove text from Canvas that I have drawn by using following
the following text is a bit lenghty as I wanted to make sure that
I am trying to load a bitmap into the canvas following the example here.
I have a WPF app that draws text on an Aero glass background. The
I'm working on a project that has me approximating text rendered as an image
I'm using following C# code to make a picture with a text in it
I am developing some prawn reports and running into an issue where any line
I have a server-side function that draws an image with the Python Imaging Library.
I have the following code to draw text centered vertically (and horizontally) in a
I have the following code which takes a touch on one button and draws

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.