-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreduceImageSize.py
More file actions
41 lines (33 loc) · 1.07 KB
/
reduceImageSize.py
File metadata and controls
41 lines (33 loc) · 1.07 KB
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
##########################
# reduceImageSize.py
##########################
from PIL import Image
import math
#
# reduces image of certain size by certain factor
#
# returns: new image with changed size
#
# im: image that is being changed
# factor: factor image is being changed by
# size: size of original im
#
def reduceImageSize(im, factor, size):
# set pixels array to incoming array of pixels
pixels = im
# get the width and height of the current image
width = size
height = size
# will be set to the shortest dimension later on
newSize = 0
# create a list to hold the new image pixel data.
new_pixels = []
# skips over certain factor of pixels depending of factor
for row in range(height // factor):
for col in range(width // factor):
index = factor * row * width + factor * col
new_pixels.append(pixels[index])
# convert into an image
newim = Image.new("RGB", (width // factor, height // factor))
newim.putdata(new_pixels)
return newim