Adding dynamic text on image

21,298

You can try the following:

  1. Use HTML5 Canvas to render your image Example: http://www.html5canvastutorials.com/tutorials/html5-canvas-images/
  2. On top of the rendered image use the HTML5 Canvas API to draw the text you want with the required font attributes Reference: https://developer.mozilla.org/en/Drawing_text_using_a_canvas

Hope its useful.

Share:
21,298
Dark Knight
Author by

Dark Knight

Updated on July 17, 2020

Comments

  • Dark Knight
    Dark Knight almost 4 years

    I'm making a website for users where they can creat customize logos. For this I need a facility to add dynamic text from text boxes which the user will fill in and the text should then appear on the the selected image. Is there any way, say for Javascript, through which I can fulfill the above scenario? Would appreciate any suggestions of how i could do this.

    My HTML so far is:

    <html>
      <body>
       <input type="text" id="submit"/>
       <img src=<?php echo $image; ?> id="toChange" alt="pic" width="60" height="60" />
      </body>
    

    and my jQuery:

    $('#submit').change(function() {
       $('#toChange').text( $('#submit').val());  
    });
    

    but I haven't been succeed so far.

  • Mitya
    Mitya almost 12 years
    All good points - but the OP wants to save the image file with the text on it, I think.
  • 18bytes
    18bytes almost 12 years
    @Utkanos and user1528490 You can save the Canvas contexts as an image file. Example here: html5canvastutorials.com/advanced/…. Hope it helps!
  • Kurtis92
    Kurtis92 over 8 years
    About save and download canvas as image, take a look here: jsfiddle.net/softvar/5hnyf