Skip to content

Commit cc338c7

Browse files
committed
Simplified code a bit
1 parent 7040e6b commit cc338c7

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

examples/epd_pillow_image.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@
4444

4545
FILENAME = "blinka.png"
4646

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))
5148

5249
# Get drawing object to draw on image.
5350
draw = ImageDraw.Draw(image)
@@ -56,19 +53,19 @@
5653

5754
# Scale the image to the smaller screen dimension
5855
image_ratio = image.width / image.height
59-
screen_ratio = width / height
56+
screen_ratio = display.width / display.height
6057
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
6360
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
6663
image = image.resize((scaled_width, scaled_height), Image.BICUBIC)
6764

6865
# 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))
7269

7370
# Display image.
7471
display.image(image)

0 commit comments

Comments
 (0)