Skip to content

Commit 7b64d27

Browse files
committed
#45, img, fmt
1 parent 74c3bdd commit 7b64d27

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

static/images/meetup-45/main.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
import numpy as np
1111
import random
1212

13-
Dim = collections.namedtuple('Dim', 'w h')
13+
Dim = collections.namedtuple("Dim", "w h")
1414

1515
files = [
16-
'tv.png',
17-
'lg.png',
18-
'24.png',
19-
'tr3.png',
16+
"tv.png",
17+
"lg.png",
18+
"24.png",
19+
"tr3.png",
2020
]
2121

22+
2223
def autopad(img, dim=Dim(800, 600)):
2324
"""
2425
Autopad creates an image of a given size and will center the given image
@@ -28,19 +29,21 @@ def autopad(img, dim=Dim(800, 600)):
2829
if c == 3:
2930
img = np.dstack([img, np.zeros((h, w, 1))])
3031
if w > dim.w or h > dim.h:
31-
raise ValueError(f'downsizing not yet supported: w={w} h={h}')
32-
norm_img = np.zeros([dim.h, dim.w, 4],dtype=np.uint8)
32+
raise ValueError(f"downsizing not yet supported: w={w} h={h}")
33+
norm_img = np.zeros([dim.h, dim.w, 4], dtype=np.uint8)
3334
norm_img[:, :, 3] = 255
3435
r = (dim.h - h) // 2
3536
c = (dim.w - w) // 2
36-
norm_img[r:r+h, c:c+w, :] = img
37+
norm_img[r : r + h, c : c + w, :] = img
3738
return norm_img
3839

40+
3941
def make_empty_image(dim=Dim(800, 600)):
40-
img = np.zeros([dim.h, dim.w, 4],dtype=np.uint8)
42+
img = np.zeros([dim.h, dim.w, 4], dtype=np.uint8)
4143
img[:, :, 3] = 255
4244
return img
4345

46+
4447
def noisy(img):
4548
alpha = img[:, :, 3]
4649
rgb = img[:, :, :3]
@@ -65,9 +68,8 @@ def main():
6568
images.extend([noisy(img) for _ in range(7)])
6669
images.extend([empty_image for _ in range(1)])
6770

68-
6971
imageio.mimsave("anim.gif", images, fps=7, loop=0)
7072

71-
if __name__ == '__main__':
72-
main()
7373

74+
if __name__ == "__main__":
75+
main()

0 commit comments

Comments
 (0)