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.
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.
– 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.
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With