18

After copying and pasting a JPG image file into Chrome, analysing the data from the Event.originalEvent.clipboardData, the image type is image/png. Why?

OS : windows 7

I think it's not possible that the image is converted when it copied to clipboard. I tried to paste it on other App, and the image can be saved as JPG.

I downloaded it from web page.

Aastha Bist
  • 324
  • 2
  • 11
Ziyu Zhou
  • 1,679
  • 2
  • 11
  • 17
  • Could it be that the image is converted to png for the clipboard? What OS are you on? – Koen. Dec 29 '15 at 10:13
  • Where did you copy it from? And what OS is this? Maybe the clipboard itself converts images into PNG. – Thilo Dec 29 '15 at 10:13
  • same thing happens to me. i paste a txt file and it ends up with the mime type "image/png". waaat? – srecnig Oct 12 '16 at 08:19
  • 2
    I read the code of webkit; It just convert! – Ziyu Zhou Nov 10 '16 at 02:43
  • The image in the clipboard is typically always BMP format (DIB in fact; Device Independent Bitmap). If you're lucky, it'll be on there as PNG, when it comes from Gimp or MS Office or something, meaning you can retain reliable alpha on it. But when you copy an image to the clipboard, the clipboard **never stores the original file**. – Nyerguds Feb 06 '19 at 10:12

1 Answers1

0

That said, it's obviously a goal to have as rich interaction as possible between native apps and websites. But the browser needs to do some "filtering" to expose only the data it knows a MIME type description for - MIME types is how we describe content on the web, it's cross-platform and hence more usable than com.apple.iWork.* strings. Also, the application might expose structured data for example in some XML format as one of the alternate parts on the clipboard.

This should pass through the clipboard api and show up as text/plain or image/jpeg+xml that we can interpret. paste works since it creates a blob object that has the correct svg extension, but clipboard paste never receives the data and only receives an alternate image/png item.

Rishabh Kushwaha
  • 429
  • 2
  • 14
  • It doesn't use text/plain or image/jpeg, though. The clipboard uses DIB (clipboard ID string "DeviceIndependentBitmap"), or a number of user-defined formats. "PNG" is making its way into that (thanks to MS Office originally I heard), which _finally_ gives us reliable alpha in clipboard images. – Nyerguds Feb 06 '19 at 10:16