I'd like to access the graphics in the linux clipboard, to save it as a file. I'm doing this in a Python/Tkinter program, so I asked about it (http://stackoverflow.com/questions/6817600/save-the-image-in-the-clipboatd-in-python-tkinter) but internally (in python) there's no hope.
Instead, I can accept to use an external utility to do it - yet I cannot find one.
Do you know of any terminal-based utility able to take the clipboard content and save it as an image file?
Steps to save a clipboard image as a JPG or PNG file: Press the 'S' key on your keyboard. Navigate to the image you want to save as JPG or PNG. After locating the image, click the 'New” button in the Snipping Tool app. If the image is stored on your computer, open it in photos first.
scrot + xclip. You can use scrot with xclip to take a screenshot and copy it to clipboard. It will capture whole of your screen and copy the image to clipboard. If you want to capture current window then use -u flag.
Loading an image from the Windows™ clipboard copies an image from the clipboard and links it to the record displayed in the current program window. The newly copied image is stored in the images folder for the software module.
Use the cp command to copy files in the Linux terminal. To copy a file on a computer with a graphical interface, you usually either drag and drop a file from one window to another window, sometimes using a modifier key.
I couldn't find any tool to do it, so I wrote this small Python script. It requires pygtk.
#!/usr/bin/python
"""
Save image from clipboard to file
"""
import sys
import glob
from optparse import OptionParser
def def_file():
"""
Return default file name
"""
files = glob.glob("img???.png")
if len(files) < 1:
return 'img001.png'
maxf = 0
for f in files:
try:
n = int(f[3:6])
maxf = max(n, maxf)
except ValueError:
pass
return 'img{:03d}.png'.format(maxf+1)
usage = """%prog [option] [filename]
Save image from clipboard to file in PNG format."""
op = OptionParser(usage=usage)
op.add_option("-o", "--open", action="store_true", dest="open", default=False,
help="Open saved file with default program (using xdg-open)")
(options, args) = op.parse_args()
if len(args) > 1:
parser.error("Only one argument expected")
sys.exit(1)
elif len(args) == 1:
fname = args[0]
else:
fname = def_file()
import gtk
clipboard = gtk.clipboard_get()
image = clipboard.wait_for_image()
if image is not None:
image.save(fname, "png")
print "PNG image saved to file", fname
if options.open:
import subprocess
subprocess.call(["xdg-open", fname])
else:
print "No image in clipboard found"
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