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

  • Home
  • SEARCH
  • 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 8728407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:38:01+00:00 2026-06-13T08:38:01+00:00

What elements are using: BACKGROUND IMAGE + IMAGE(shape) + TEXT in canvas Problem: Not

  • 0

What elements are using: BACKGROUND IMAGE + IMAGE(shape) + TEXT in canvas

Problem: Not showing text above a image of background in canvas.

What I expected: Show a text above of image with background image of color.

What I have: If removed image makeShape() function it will show text. Notice: image function have a background color.


This is a HTML form code:

<!doctype html>
<html lang="en">
    <head>
        <title>Canvas text above picture</title>    
        <meta charset="utf-8">
        <style>
            canvas {
                border: 2px solid black;
            }
        </style>
    </head>
    <body>
<form>
<p>
<label for="backgroundColor">Text font:</label>
<select id="backgroundColor">
<option value="white" selected="selected">White</option>
<option value="black">Black</option>
</select>
</p>
<p>
<label for="txt">Text font:</label>
<textarea id="txt" cols="40" rows="3"></textarea>
</p>

<p>
<input type="button" id="previewButton" value="Preview">
</p>
</form>
        <canvas id="myCanvas" width="600" height="500"></canvas>
        <script src="canvasshirt.js"></script>

    </body>
</html>

A canvasshirt.js code:

window.onload = function() {
    var button = document.getElementById("previewButton");
    button.onclick = previewHandler;
}

function previewHandler() {

    var ca = document.getElementById("myCanvas");
    var co = ca.getContext("2d");

    var bgcolor = document.getElementById("backgroundColor");
    var index = bgcolor.selectedIndex;
    var fgColor = bgcolor[index].value;

    var text = document.getElementById("txt").value;

    drawText(co, text); // ! - this should show text above of drawBckg() function

    drawBckg(ca, co, 600, 500, fgColor); // this draw a background of picture below of text
}


function drawBckg(ca, co, w, h, color)
{
    makeShape(co);

    co.fillStyle = color;
    co.fillRect(0, 0, w, h);
}

function makeShape(co)
{
    var shapeimg = new Image();

    shapeimg.src = "shape2.png";

    shapeimg.onload = function() {
        co.drawImage(shapeimg, 170, 10, 233, 350);
    }
}

function drawText(co, text)
{
    co.font = " 13px Arial";
    //co.font = "bold 1em sans-serif";
    co.textAlign = "left";
    co.fillText(text, 20, 40);
}

FIXATION TRY…

When is changing of function sorting of source code it will result below:

drawBckg(ca, co, 600, 500, fgColor);
drawText(co, text);

Image of example (text is below of image):

Blue text is below of <code>makeShape()</code> picture with turned off background

  • 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-06-13T08:38:02+00:00Added an answer on June 13, 2026 at 8:38 am
    drawBckg(ca, co, 600, 500, bgcolor, function(){
        drawText(co, text, fgColor);
    }); 
    

    …

    function drawBckg(ca, co, w, h, color, callback)
    {
        makeShape(co, callback);
    
        co.fillStyle = color;
        co.fillRect(0, 0, w, h);
        callback();  // draw the text here as a fallback if the image doesn't load
    }
    
    function makeShape(co, callback)
    {
        var shapeimg = new Image();
    
        shapeimg.src = "shape2.png";
    
        shapeimg.onload = function() {
            co.drawImage(shapeimg, 170, 10, 233, 350);
            callback();  // draw the text after drawing the image.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am setting the background-image of some elements using css (some elements have no
I have CSS with background-image's elements that refer to another site. Problem is, that
I have a button image I'm using as a background image for some links.
I'm using -webkit-background-clip to restrict a background image to the text in an h2
How can I select elements (using jQuery) that do not contain any elements? For
So I'm trying to create canvas elements using the information passed back by The
How to I hide and show HTML elements using JQuery without any special effects?
I have a list and I'm adding elements using RPUSH which returns the updated
I have a view that renders a list elements using the following template :
I have an iPhone application using UINavigationController and would like to customize the elements

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.