-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.py
50 lines (33 loc) · 1.25 KB
/
adapter.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
50
from typing import Protocol
import random
class Pillow:
def __init__(self, filename):
self.filename = filename
def resize(self, new_size: tuple[int, int]):
print(f"resizing {self.filename} to {new_size} ...")
class GraphicsMagick:
def __init__(self, filename):
self.filename = filename
def resize_image(self, width: int, height: int):
print(f"resizing {self.filename} to {width}x{height} ...")
class AwesomeLib:
def __init__(self, filename):
self.filename = filename
def stretch(self, factor):
print(f"stretching {self.filename} {factor} times...")
class SupportsImageResize(Protocol):
def resize(self, new_size: tuple[int, int]) -> None:
...
class GraphicsMagickAdapter:
def __init__(self, filename):
self.filename = filename
self._gm = GraphicsMagick(filename)
def resize(self, new_size: tuple[int, int]) -> None:
self._gm.resize_image(new_size[0], new_size[1])
class AwesomeLibAdapter:
def __init__(self, filename):
self.filename = filename
self._awesome = AwesomeLib(filename)
def resize(self, new_size: tuple[int, int]) -> None:
factor = random.randrange(0, 500) / 100.0
self._awesome.stretch(factor)