forked from macr1408/XFCE-Spotify-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageresizer.py
32 lines (28 loc) · 822 Bytes
/
imageresizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from PIL import Image
from resizeimage import resizeimage
import sys, os, wget
try:
workingdir = str(sys.argv[1])
url = str(sys.argv[2])
size = int(sys.argv[3])
except IndexError:
raise Exception("missing arguments")
os.chdir(workingdir)
if os.path.exists('./prevArtUrl.txt'):
with open('./prevArtUrl.txt') as uf:
prevurl = uf.read()
if prevurl == url:
print('URL is the same, skipping redownload and resize.')
exit()
try:
os.remove('./img.png')
os.remove('./out.png')
except Exception as e:
pass
wget.download(url, './img.png')
with open('./img.png', 'r+b') as f:
with Image.open(f) as image:
cover = resizeimage.resize_height(image, size)
cover.save('./out.png', image.format)
with open('./prevArtUrl.txt', 'w') as uf:
uf.write(url)