Last active
June 15, 2022 13:56
-
-
Save htlin222/001557d693d2af385f22e331cde81a19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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