Skip to content

Instantly share code, notes, and snippets.

@htlin222
Last active June 15, 2022 13:56
Show Gist options
  • Save htlin222/001557d693d2af385f22e331cde81a19 to your computer and use it in GitHub Desktop.
Save htlin222/001557d693d2af385f22e331cde81a19 to your computer and use it in GitHub Desktop.
import pyimgur
import pyperclip
from PIL import Image, ImageGrab
import os
import time
# define the t to make the image name
t = time.localtime()
t =time.strftime("%y-%m-%d_%H_%M_%S", t)
CLIENT_ID = "YOURCLIENTID" # get if from https://imgur.com/account/settings/apps
title = "Uploaded with PyImgur"
image_path = "Pictures"
if not(os.path.exists(image_path)):
os.mkdir(image_path)
image_path = f"{image_path}/image-{t}.png"
image = ImageGrab.grabclipboard()
if not image is None: # check if there's image in the clipboard
image = image.save(image_path)
im = pyimgur.Imgur(CLIENT_ID)
uploaded_image = im.upload_image(image_path, title=title)
# print(uploaded_image.title)
# print(uploaded_image.link)
# print(uploaded_image.type)
link = uploaded_image.link
result= f"![image_{t}]({link})"
pyperclip.copy(result)
spam = pyperclip.paste() # save the result to system clipboard
os.remove(image_path) # comment this line if you want to keep the image
else:
print("no image")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment