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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:35:44+00:00 2026-06-17T03:35:44+00:00

JsFiddle: http://jsfiddle.net/K34a7/ I am creating a div and saving image in it. I want

  • 0

JsFiddle: http://jsfiddle.net/K34a7/ I am creating a div and saving image in it. I want to know how to detect the width of the part written in image so that i can dynamically assign the width size of the div and not the whole image?

document.getElementById('text').addEventListener('keyup', function (){
tCtx.canvas.width = tCtx.measureText(this.value).width;
var t = this.value.split('\n');
tCtx.canvas.height = t.length*10;

console.log(t);
var y = 10;
for(var i=0; i<t.length; i++, y+=10) {
tCtx.fillText(t[i], 0, y);
}

//console.log('Value: ' + this.value);
imageElem.src = tCtx.canvas.toDataURL();
//console.log(imageElem.src);
}, false);
  • 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-17T03:35:45+00:00Added an answer on June 17, 2026 at 3:35 am

    You’re already using measureText in your code. Just add a reference to the width like so

    var textWidth = tCtx.measureText(this.value).width;
    

    textWidth will contain the width of the text on the canvas.

    Demo

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

Sidebar

Related Questions

I have made a JSFiddle ( http://jsfiddle.net/wpC57/2 ) that showcases my problem. I want
I have the following code that is working fine in jsfiddle - http://jsfiddle.net/darkajax/FHZBy/ I've
I have 2 internal div's within a main div JSfiddle - http://jsfiddle.net/uwdnH/ Illustration -
JSFiddle: http://jsfiddle.net/M2ALY/3/ My goal is to make a module that I can use and
jsFiddle: http://jsfiddle.net/4z2Vx/ I'm trying to create a multi-column dropdown/menu widget. The image on the
Jsfiddle: http://jsfiddle.net/yJJs7/ Javascript: function main(){ var centerx=250; var centery=250; var degrees=0; var div=document.getElementById('test'); var
Check out this jsfiddle http://jsfiddle.net/Y7fEW/ . I'm trying to get the tan div on
jsfiddle: http://jsfiddle.net/PBvk9/ I want the arrow for its respective tab to show up only
JSFiddle: http://jsfiddle.net/eFNAF/17/ Notice the green background and the image overlaying it. The previous/next buttons
I have this jsFiddle: http://jsfiddle.net/HMZuh/1/ Which contains this html <div ng-app ng:controller=ShowHideController> <div ng-show='showMe'>

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.