-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresizeSquare.py
More file actions
46 lines (34 loc) · 1.09 KB
/
resizeSquare.py
File metadata and controls
46 lines (34 loc) · 1.09 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
42
43
44
45
46
#######################
# resizeSquare.py
#######################
from PIL import Image
import math
#
# changes image to newSize x newSize pixels strickly
#
# returns: new image that is newSize x newSize pixels
#
# im: array of pixels from image function is getting new size from
# newsize: new size of photo
# size: old size of image
#
def resizeSquare(im, newSize, size):
# set pixels array to incoming array of pixels
pixels = im
# get the width and height of the current image
width = size
height = size
# create a list to hold the new image pixel data.
new_pixels = []
# the difference on either side of newSize x newSize square that is getting
# cut by center of current image
dif = (width - newSize) // 2
# keeps track of the row of the photo that the pixels are from
row = dif + 1
while row < (height - dif):
rowIndex = row * width
for col in range(newSize):
i = row * width + dif + col
new_pixels.append(pixels[i])
row += 1
return new_pixels