-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolution conversion.py
More file actions
27 lines (25 loc) · 884 Bytes
/
Resolution conversion.py
File metadata and controls
27 lines (25 loc) · 884 Bytes
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
#!/usr/bin/python
from PIL import Image
import os
image_file = "leo.jpg"
img_org = Image.open(image_file)
# get the size of the original image
width_org, height_org = img_org.size
# set the resizing factor so the aspect ratio can be retained
# factor > 1.0 increases size
# factor < 1.0 decreases size
factor = 0.05
width = int(width_org * factor)
height = int(height_org * factor)
# best down-sizing filter
img_anti = img_org.resize((width, height), Image.ANTIALIAS)
# split image filename into name and extension
name, ext = os.path.splitext(image_file)
# create a new file name for saving the result
new_image_file = "%s%s%s" % (name, str(factor), ext)
img_anti.save(new_image_file)
print("resized file saved as %s" % new_image_file)
# one way to show the image is to activate
# the default viewer associated with the image type
import webbrowser
webbrowser.open(new_image_file)