I'm trying to insert an image in a canvas and after that I want to insert an input text in the same canvas, but I can't do it. How can I fix this problem?
Now, I want that the user insert a draggable text in the actual canvas. The people say that using Fabric.js is easy, but I can't get it working:
canvas = document.getElementById("canvasThumbResult");
var context = canvas.getContext("2d");
var img = document.getElementById("target");
context.drawImage(img, getX, getY, getWidth, getHeight, 0, 0, 238.11023622,332.598425197);
Using Scrawl.js:
(Disclaimer: I am the developer of this library)
Working demo: over at jsFiddle
Here is how to add user-specified text on an image and allow the text to be dragged
This solution uses a canvas library called KineticJS and jQuery to simplify the task.
Here’s how it works:
draggable:true
when creating the objectHere’s the code that makes it all work…
Create the Kinetic Stage (this activates the HTML canvas)
Create a new image object in JavaScript (this loads your image into an object)
Create a new Kinetic Image object and put your new image in the Kinetic Image object
When the user types text in the input and hits the “Add” button…
Create a new Kinetic Label object using the user’s text
To make the new text label draggable, just set
draggable:true
when creating the objectYou can download the Kinetic library and learn more with examples in HTML5 Canvas KineticJS Label Tutorial. You can download the jQuery library and learn more with examples here at the jQuery home page. jQuery is a great library for eliminating cross-browser inconsistencies.
Here is code and a Fiddle: http://jsfiddle.net/m1erickson/pQYz9/