clipboard to image file
This commit is contained in:
1
bin/clip2img
Symbolic link
1
bin/clip2img
Symbolic link
@@ -0,0 +1 @@
|
||||
../files/clip2img
|
||||
33
files/clip2img
Executable file
33
files/clip2img
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
import pygtk,gtk,os,sys
|
||||
pygtk.require('2.0')
|
||||
from argparse import ArgumentParser
|
||||
|
||||
|
||||
def write_image(f):
|
||||
|
||||
clipboard = gtk.clipboard_get()
|
||||
image = clipboard.wait_for_image()
|
||||
if image==None:
|
||||
sys.stderr.write("No image in clipboard!\n")
|
||||
sys.exit(1)
|
||||
image.save(f, type_str(f))
|
||||
|
||||
def type_str(f):
|
||||
filename, file_extension = os.path.splitext(f.lower())
|
||||
file_extension=file_extension[1:]
|
||||
if file_extension=="jpg":
|
||||
return 'jpeg'
|
||||
if file_extension=="tif":
|
||||
return 'tiff'
|
||||
|
||||
return file_extension
|
||||
|
||||
parser=ArgumentParser(description="Write image from clipboard to image file. Extension jpg/png/tif/ico/bmp.")
|
||||
parser.add_argument('image', action="store")
|
||||
opts=parser.parse_args()
|
||||
|
||||
if (os.path.exists(opts.image)):
|
||||
sys.stderr.write("Image already exists!\n")
|
||||
sys.exit(1)
|
||||
write_image(opts.image);
|
||||
Reference in New Issue
Block a user