-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImage.py
49 lines (35 loc) · 896 Bytes
/
Image.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from PIL import Image
import os
import sys
import math
import settings
def getRGB(img, x, y):
img = img.convert("RGBA")
r, g, b, a = img.getpixel((x, y))
return r, g, b, a
def resize(img):
img = Image.open(img)
x, y = getSize(img)
maxRes = settings.resolution
aspectRatio = max(x, y) / min(x, y)
if x == max(x, y):
x = maxRes
y = int(maxRes / aspectRatio)
else:
x = int(maxRes / aspectRatio)
y = maxRes
return img.resize((int(x), int(y)))
# https://gist.github.com/revolunet/848913
def extractFrames(inGif):
frame = Image.open(inGif)
nframes = 0
while frame:
frame.save('pictures/frames/{}.png'.format(nframes), 'PNG')
nframes += 1
try:
frame.seek(nframes)
except EOFError:
break
return True
def getSize(img):
return img.size