viliusle / miniPaint

online image editor
http://viliusle.github.io/miniPaint/
Other
2.74k stars 634 forks source link

[Feature Request] Copying or saving image to clipboard #205

Closed Giwayume closed 3 years ago

Giwayume commented 3 years ago

This is useful for quick edits in social media, so you can copy an image you've found into miniPaint, edit, then copy the edited version to the clipboard and paste it on Facebook, Discord, etc.

The navigator clipboard API allows this, but it's a pretty recent addition to most browsers. We can implement it and use permissions API to detect whether the functionality is available, and hide it if not. Should be supported in all major browsers soon-ish.

My thought is "Ctrl + C" will copy the rasterized data of the current layer to the clipboard (if not focused in a text input, or using selection tool). At the same time if it's a vector layer, store in memory the vector data as well as a hash of the rasterized data for comparison. "Ctrl + V" will check if vector data is in memory associated with the last in-editor copy, and if so, compares the hash of the rasterized layer stored in memory to a hash of the image in the clipboard. If they're the same hash, creates a copy of the vector data instead of creating an image layer from the clipboard data. This ensures copy/paste doesn't auto-rasterize vector layers, while also making a rasterized version of the vector layer available to other programs.

Also File -> Save As... will have an option to save to the clipboard.

https://dev.to/viclafouch/the-new-way-to-copy-an-image-or-a-text-to-clipboard-in-javascript-2n1g