Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload image into HTML5 canvas

I am currently using http://paperjs.org to create an HTML5 canvas drawing app. I want to let users upload images into the canvas. I know I need to make a login and signup but is there an easier way? I have seen the HTML5 drag and drop upload.

like image 974
user1438026 Avatar asked Jun 06 '12 00:06

user1438026


People also ask

How do I upload an image to canvas?

Step 1: Open the assignment in your Canvas Student App. Step 2: Click on Submit Assignment. Step 3: Choose File Upload. Step 4: Choose Library, the choose All Photos.

Why can't I upload images on canvas?

Canva upload errors happen because your image file is larger than 25mg, your image file is in the wrong format, your computer is offline, you're logged out, or Canva is down. As long as the Canva website is working, most designers can fix upload errors on their own.


1 Answers

I assume you mean, to load an image into the canvas and not uploading the image from the canvas.

It'd probably be a good idea to read through all the canvas articles they have over here https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial/Using_images

But basically what you want to do is create an image in javascript, and set the image.src = to whatever the file location is. In the case of loading images from the user on their end, you're going to want to use the File System API.

Threw together a brief example here: http://jsfiddle.net/influenztial/qy7h5/

function handleImage(e){     var reader = new FileReader();     reader.onload = function(event){         var img = new Image();         img.onload = function(){             canvas.width = img.width;             canvas.height = img.height;             ctx.drawImage(img,0,0);         }         img.src = event.target.result;     }     reader.readAsDataURL(e.target.files[0]);      } 
like image 76
DerekR Avatar answered Sep 28 '22 04:09

DerekR