Getting a graphic on the clipboard to the disk?

I have a graphic on the clipboard on ubuntu.

What's the quickest way to get it onto disk as a png or jpg?


xclip

xclip (man page) is on official repos of major distros (pasteimg it isn't and last update was on 2011).

For me the quickest way is using terminal, going to the desired folder (maybe using autojump) and then just run clipboard2photo, which is an alias I created to the following command:

xclip -selection clipboard -t image/png -o > "$(date +%Y-%m-%d_%T).png"  # Use "Screenshot from $(date "+%Y-%m-%d %H-%M-%S").png" if you like GNOME filename format.

With something on clipboard you can get all possible targets with: xclip -selection clipboard -o -t TARGETS

GNOME Shell shortcuts

On GNOME Shell (Ubuntu 17.10+) we have built in shortcuts to save screenshots directly to ~/Pictures:

screenshot

Hints to remember them:

  • Ctrl → to clipboard (else to ~/Pictures)
  • Alt → Current window
  • Shift → Area/Surface

I usually disable "Print" to avoid generating garbage on ~/Pictures if I miss F12 (which I use a lot with Guake) and accidentally press it.


Tip 1: Put your aliases on ~/Dropbox/.mybashrc (or maybe better .myprofile) and then include this file from .bashrc.

[ -r ~/Dropbox/.mybashrc ] && source ~/Dropbox/.mybashrc

This way you will have them on all your current and future devices. Of course you can also have a ~/.dotfiles with a git repo.

Tip 2: In the same way you can: thisOutputMarkdown | pandoc -s -f markdown -t html | xclip -selection clipboard -t text/html to get formatted HTML to clipboard.
If you have the Markdown text on clipboard replace thisOutputMarkdown with xsel -b.

Note: It seems there is some work to be done about xclip on Wayland (echo $XDG_SESSION_TYPE). Please help developers on this issue. Meanwhile maybe wl-paste (from wl-clipboard) might work:

wl-paste -t image/png > "$(date +%Y-%m-%d_%T).png"

I just threw together a quick python script that will paste a clipboard image to a file.

It's very basic but it does the job but could be easily extended.

PasteImg


I've been googling for a while and it seems as if there is no clipboard manager yet that supports pasting of an image directly in a folder, even though there is this Nautilus feature request.

So the answer would be paste it in a graphics application (e.g. gimp) and save it.


With Gimp.

Ctrl+Shift+V

"creates" a new image from the one in the clipboard.

Ctrl+Shift+E

"exports" it, in other words it offers a "save" kind of dialog box for formats other than .xcf.


Ah: you ask "quickest"?! Weellll, maybe if you already have Gimp open on the desktop ;)


I've created pimg to replace PasteImg. It runs on Python>=3.5 with PyGObject. (Successor to PyGTK used by PasteImg)

pimg can install via pip:

pip install pimg

Like PasteImg, it runs:

pimg image.png

Please try it.