Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get animated gif image from browser clipboard api?

I am testing the following code, and when I copy an animated gif and paste it to web page, I see image/png in the console - instead of image/gif as expected.

Why?

document.onpaste = function(event) {
  console.log(event.clipboardData.items[1]['type']); // 'image/png'
};

How can I match a gif image?

You can test it at this jsfiddle with this gif image for example.

like image 938
milushov Avatar asked Feb 18 '13 10:02

milushov


People also ask

How do you save a GIF to your clipboard?

To copy an Animated GIF from a website:Right-click the image and click "Save Image As" (or your browser's equivalent), saving it somewhere on your computer. In Screen2Gif , hit Ctrl + Shift + O or click Media under File menu.. Choose the image from the location on your computer where you saved it.

How do I save an animated GIF in Chrome?

– Click on the GIF to get its detailed page. – Then right-click on it and choose the “Save image as…” option. – Select a folder to save the GIF and rename the GIF file. – Press the Save button to save the GIF.


1 Answers

The CF_GIF clipboard format is very seldomly used. Most app copy images to the clipboard only as CF_BITMAP, CF_ENHMETAFILE, or CF_DIB. Then when you paste, the data is converted to whatever format the target application perfers, such as PNG or Bitmap. So in your case, the GIF was likely copied to the clipboard as a Bitmap, then converted to PNG when pasting. All of the animation frames of your GIF were lost. In order to preserve, you need to do drag/drop or emulate file pasting with CF_HDROP, CF_FileName, etc..

like image 75
Chris Thornton Avatar answered Sep 19 '22 06:09

Chris Thornton