/
get_image.py
35 lines (26 loc) · 886 Bytes
/
get_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
"""Retrieve test image, resize it, and store under new filename."""
#
# (C) Copyright 2021 Pavel Tisnovsky
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Pavel Tisnovsky
#
import urllib.request
from PIL import Image
# URL to the test image
url = "https://homepages.cae.wisc.edu/~ece533/images/fruits.png"
original_filename = "fruits_.png"
resized_filename = "fruits.png"
# try to retrieve the test image from given URL
urllib.request.urlretrieve(url, original_filename)
# read image from file
img = Image.open(original_filename)
# resize it
resized = img.resize((128, 128), Image.BILINEAR)
# and store under new name
resized.save(resized_filename)