最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to insert input text into image? - Stack Overflow

matteradmin1PV0评论

I want to develop extension for magento which help to create custom t-shirt but i don't know how to do it.I want to provide functionality like this site +Repair/A252/329/item.htmlDead link

here you enter the name and then name automatically insert to image .i want to provide this exactly but didn't get right matter

I want to develop extension for magento which help to create custom t-shirt but i don't know how to do it.I want to provide functionality like this site http://www.inkpixi./item/ATV+Repair/A252/329/item.htmlDead link

here you enter the name and then name automatically insert to image .i want to provide this exactly but didn't get right matter

Share Improve this question edited Apr 21, 2018 at 21:34 Roko C. Buljan 207k41 gold badges328 silver badges340 bronze badges asked Apr 8, 2013 at 9:25 nehranehra 1581 silver badge8 bronze badges 3
  • This is done with server-side image processing, not jQuery – Bill Commented Apr 8, 2013 at 9:31
  • Would not position a <span> above (on top of) the image be enough? At least for starters... – J.G.Sebring Commented Apr 8, 2013 at 9:34
  • i am not clear about server-side image processing what do you mean by that, – nehra Commented Apr 8, 2013 at 11:47
Add a ment  | 

1 Answer 1

Reset to default 13

You can do it so simply with canvas

var canvas = document.createElement('canvas'),
	  ctx = canvas.getContext('2d');

canvas.width  = 200;
canvas.height = 200;
document.body.appendChild(canvas);

function sendToCanvas( ob ){
  var img = new Image();
  img.addEventListener('load', function(){
    ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
    ctx.font = ob.fontWeight+' '+ob.fontSize+' '+ob.fontFamily;
    ctx.textAlign = 'center';
    ctx.fillStyle = ob.color;
    ctx.fillText(ob.text, canvas.width/2, canvas.height/2.5);
  });
  img.src = ob.image;
}

// Defaults
var cvsObj = {
    text       : "stackoverflow",
    image      : "http://i.imgur./hqayV16.jpg",
    fontFamily : "Arial",
    fontWeight : "bold",
    fontSize   : "90%",
    color      : "rgba(244, 128, 36, 0.7)"
};

sendToCanvas( cvsObj ); // Send default data on init

document.getElementById("text").addEventListener("input", function(){
  cvsObj.text = this.value; // Modify cvsObj text
  sendToCanvas( cvsObj );   // Send custom data on input
});

 
Text: <input id="text" type="text"><br>

Right click and Save as :) !

Post a comment

comment list (0)

  1. No comments so far