|
44 | 44 |
|
45 | 45 | FILENAME = "blinka.png"
|
46 | 46 |
|
47 |
| -width = display.width |
48 |
| -height = display.height |
49 |
| - |
50 |
| -image = Image.new('RGB', (width, height)) |
| 47 | +image = Image.new('RGB', (display.width, display.height)) |
51 | 48 |
|
52 | 49 | # Get drawing object to draw on image.
|
53 | 50 | draw = ImageDraw.Draw(image)
|
|
56 | 53 |
|
57 | 54 | # Scale the image to the smaller screen dimension
|
58 | 55 | image_ratio = image.width / image.height
|
59 |
| -screen_ratio = width / height |
| 56 | +screen_ratio = display.width / display.height |
60 | 57 | if screen_ratio < image_ratio:
|
61 |
| - scaled_width = image.width * height // image.height |
62 |
| - scaled_height = height |
| 58 | + scaled_width = image.width * display.height // image.height |
| 59 | + scaled_height = display.height |
63 | 60 | else:
|
64 |
| - scaled_width = width |
65 |
| - scaled_height = image.height * width // image.width |
| 61 | + scaled_width = display.width |
| 62 | + scaled_height = image.height * display.width // image.width |
66 | 63 | image = image.resize((scaled_width, scaled_height), Image.BICUBIC)
|
67 | 64 |
|
68 | 65 | # Crop and center the image
|
69 |
| -x = scaled_width // 2 - width // 2 |
70 |
| -y = scaled_height // 2 - height // 2 |
71 |
| -image = image.crop((x, y, x + width, y + height)) |
| 66 | +x = scaled_width // 2 - display.width // 2 |
| 67 | +y = scaled_height // 2 - display.height // 2 |
| 68 | +image = image.crop((x, y, x + display.width, y + display.height)) |
72 | 69 |
|
73 | 70 | # Display image.
|
74 | 71 | display.image(image)
|
|
0 commit comments