import requests as req import os, bs4 import numpy as np comicn = np.random.randint(3000) url = f'https://xkcd.com/{comicn}' os.makedirs('xkcd', exist_ok=True) res = req.get(url) soup = bs4.BeautifulSoup(res.text) comicElem = soup.select('#comic img') comicUrl = 'http:' + comicElem[0].get('src') print(comicUrl) res = req.get(comicUrl) imageFile = open(os.path.join('/home/spaghettifiedcat/Documents/Python/xkcd_downloader/xkcd', os.path.basename(comicUrl)), 'wb') for chunk in res.iter_content(1): imageFile.write(chunk) imageFile.close() from PIL import Image, ImageOps print(os.path.basename(comicUrl)) im = Image.open(f'Documents/Python/xkcd_downloader/xkcd/{os.path.basename(comicUrl)}') im_invert = ImageOps.invert(im) im_invert.save('Documents/Python/xkcd_downloader/xkcd/inverteg.jpeg', quality=95) image = Image.open("Documents/Python/xkcd_downloader/xkcd/inverteg.jpeg") right = 100 left = 100 top = 100 bottom = 100 width, height = image.size new_width = width + right + left new_height = height + top + bottom result = Image.new(image.mode, (new_width, new_height), 0) result.paste(image, (left, top)) result.save('Documents/Python/xkcd_downloader/xkcd/inverteg.jpeg') os.system('hyprctl hyprpaper reload "eDP-1,contain:~/Documents/Python/xkcd_downloader/xkcd/inverteg.jpeg"')