Skip to content

Instantly share code, notes, and snippets.

@zno-man
Created October 14, 2020 20:34
Show Gist options
  • Save zno-man/f2ac90bbc9b13cfdf6aae6a48320c196 to your computer and use it in GitHub Desktop.
Save zno-man/f2ac90bbc9b13cfdf6aae6a48320c196 to your computer and use it in GitHub Desktop.
you can use this to save an image that has been copied to the clipboard (either using print screen or using windows key+shift+s) to a jpeg file just by double clicking,(i have tested it only on windows))
from PIL import ImageGrab
from win32 import win32clipboard
import time
def makeimg():
name=time.time()
name=(str(name))
im = ImageGrab.grabclipboard()
try:
im.save(name+'.jpeg','JPEG')
except:
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
print("this text was previously copied to the clipboard not an image :\n---------------------------------------------------------------------------------------- \n",data)
print("\n----------------------------------------------------------------------------------------")
win32clipboard.CloseClipboard()
else:
print("\n\n the image has been saved with the name {}.jpeg ".format(name))
time.sleep(1)
makeimg()
from PIL import ImageGrab
from win32 import win32clipboard
import time
def makeimg():
name=time.time()
name=(str(name))
im = ImageGrab.grabclipboard()
try:
im.save(name+'.jpeg','JPEG')
except:
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
print("this text was previously copied to the clipboard not an image :\n---------------------------------------------------------------------------------------- \n",data)
print("\n----------------------------------------------------------------------------------------")
win32clipboard.CloseClipboard()
else:
print("\n\n the image has been saved with the name {}.jpeg ".format(name))
time.sleep(1)
makeimg()
from PIL import ImageGrab
from win32 import win32clipboard
import time
def makeimg():
name=time.time()
name=(str(name))
im = ImageGrab.grabclipboard()
try:
im.save(name+'.jpeg','JPEG')
except:
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
print("this text was previously copied to the clipboard not an image :\n---------------------------------------------------------------------------------------- \n",data)
print("\n----------------------------------------------------------------------------------------")
win32clipboard.CloseClipboard()
else:
print("\n\n the image has been saved with the name {}.jpeg ".format(name))
time.sleep(1)
makeimg()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment