I have a paste handler which takes an image in the clipboard and uploads it to the server. I can successfully access the clipboard data, but if the clipboard image data has a resolution higher than 72ppi, it gets downsampled to 72ppi.
This is especially annoying when taking a screenshot on a MacBook Retina to the clipboard (via Command-Control-Shift-3
. The clipboard data of the image is at 144ppi—this is the ppi that appears when I paste into Photoshop. However, when I paste into the browser, the image is downsampled by half.
I've Google searched for the paste day trying to find a solution, but no luck. I assume the downsampling is happening with the .getAsFile() method.
Here's simplified version of the code:
$('html').bind('paste', function(e) {
e.preventDefault();
var item = (e.clipboardData || e.originalEvent.clipboardData).items[0];
var type = item.type.split('/').shift();
if (type == "image"){
var file = item.getAsFile();
var blob = URL.createObjectURL(file); // Blob
window.open(blob);
}
});
Here is a JSFiddle:
http://jsfiddle.net/zd5pX/1/
To repro the issue on a Retina machine:
- Take a screenshot to the clipboard
Command-Control-Shift-3
. - Click on the HTML pane in the JSFiddle
- Paste (
Command-V
) - A new window will appear showing the pasted image.
- Now open Photoshop, create a new document, and paste again.
- Observe that the image resolution and size differs between the browser and Photoshop.
Any suggestions would be greatly appreciated!