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 1002989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:54:35+00:00 2026-05-16T07:54:35+00:00

Kind of stuck with this thing, that’s why need help please. I am using

  • 0

Kind of stuck with this thing, that’s why need help please. I am using HTML5 and JavaScript to insert text on an image and create a new image with the text on it. Everything is fine if I am adding the text manually, however if I am trying to pass the text to the function as a value, its not happening. Here’s the function code below

 function draw_text(topt,bott){
  var canvas = document.getElementById("e");
  var context = canvas.getContext("2d");
    var img = new Image();
    img.src = "testimage.jpg";
    img.onload = function() 
    {
    context.drawImage(img, 0, 0);
    draw_text();
    };
    var toptext =  this.topt;
    var bottomtext =  this.bott;
    context.font = "12px Arial";
    context.fillStyle = "white"; 
    context.strokeStyle = 'black';
    context.fillText(toptext, (img.width-context.measureText(toptext).width)/2, 40);
    context.strokeText(toptext, (img.width-context.measureText(toptext).width)/2, 40);
    context.fillText(bottomtext, (img.width-context.measureText(bottomtext).width)/2, 350);
    };

And I am calling this function by

draw_text('Text 1','Text 2');

But I either the canvas is not visible at all or it comes with the text ‘Undefined’. What am I doing wrong? By the way, if it’s any important I am doing this code in a codeigniter view file.

  • 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-16T07:54:35+00:00Added an answer on May 16, 2026 at 7:54 am

    You are not using ‘this’ correctly.

    Replace:

    var toptext =  this.topt;
    var bottomtext =  this.bott;
    

    With:

    var toptext =  topt;
    var bottomtext =  bott;
    

    ***Also, I just noticed you have a recursive call to “draw_text()” with no parameters in the definition of draw_text, which is also a problem.

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

Sidebar

Related Questions

This is a minor presentation thing that has bugged me for ages: http://gyazo.com/e5bed138e234fef7f570bd36edee3edd.png Checkout
I have a Canvas that i draw text on. (this is quite advanced i
I'm kind of like stuck trying to implement YUI autocomplete textbox. here's the code:
Kind of a weird question, but. I need to have a list of strings
this kind of follows on from another question of mine. Basically, once I have
What kind of performance implications are there to consider when using try-catch statements in
As kind of a follow up to this question about prefixes , I agree
My current thinking: I need a certain module that will let me access the
First of all, I am sorry that this is not a 'question that can
I have just begun scraping basic text off web pages, and am currently using

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.