Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one paste images into a Web App? What solutions are available? HTML 5 Canvas?

I'm currently building a very bare bones web app, that had the requirement of being able to copy an image while broswing the web, and then pasting it onto my page.

I know that this type of functionality IS possible - as I've pasted images into gmail while writing messages, and into Tumblr (I believe they use TinyMCE as their editor).

After long searching - I've been saddened by the poor quality of explanation for the available solutions out there.

This is what I've gathered:

$(document).bind('paste', function(e){
console.log(e);
})

Inspecting the event object, it seems that data is only included when there is text (in Chrome anyways).

I am aware that IE has a clipboardData object which gives you access to the clipboard contents.

I've also heard of possible solutions using Flash, Java Applets, and HTML 5 Canvas - but I haven't yet been able to find good write ups explaining those solutions.

Anyone done this successfully, and can suggest best practices?

like image 398
nicoslepicos Avatar asked Nov 28 '10 20:11

nicoslepicos


People also ask

How do you paste a picture on canvas?

Ctrl + V (for Windows) or Cmd + V (for Mac) for pasting content. You can use this keyboard shortcut for text, images, files, folders, and links.

What is image canvas?

The Canvas Size command is used for adding space around a photo or essentially cropping the image by reducing the available space. More Detail: For example, let's assume you have an image that is currently sized at 8-inches by 12-inches at 300 pixels per inch (2,400 by 3,600 pixels).


1 Answers

This works fine in Chrome. Here's a live example supporting getting image data in pure JavaScript with no servers involved: http://strd6.com/2011/09/html5-javascript-pasting-image-data-in-chrome/

like image 107
Daniel X Moore Avatar answered Sep 19 '22 13:09

Daniel X Moore