27

I have a graphic on the clipboard on ubuntu.

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

25

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"
7

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

2

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.

2

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 ;)

2
  • Does GIMP modify the image during export?
    – Flux
    Sep 6 at 21:36
  • @Flux well, if you export into a lossy compression format, like jpeg, then certainly. Other than that, it may apply its own color profile (I'm not sure however), and it may suggest adding some meta information according to the corresponding file format (can be overridden in the save dialogs).
    – Levente
    Sep 9 at 13:58
0

I needed this for my Emacs org-download-screenshot setup, so here's a Python script I made that depends only on Python 3.8 (no additional packages), xclip and ImageMagick convert: https://github.com/cpbotha/save_image_from_clipboard

It will save out whatever image you have in the clipboard, to whatever format you specify on the command-line.

0

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.

0

xclip wasn't working for me and I coudn't understand why until I realized that if you are running Wayland, for example in Ubuntu 21.04, you can't use xclip. You have to use wl-paste from the wl-clipboard package. For example:

wl-paste -t image/png > filename.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.