-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertOGIntoSquare.py
More file actions
52 lines (39 loc) · 1.6 KB
/
convertOGIntoSquare.py
File metadata and controls
52 lines (39 loc) · 1.6 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
47
48
49
50
51
52
##############################
# convertOGIntoSquare.py
##############################
from PIL import Image
import imageSetting
import getSquare
import math
import reduceImageSize
import resizeSquare
#
# converts original image into a square of 100x100
#
# imgName: name of image that is being changed
# inDir: where photo is located
# outDir: where photo is being stored
# imgNum: img number (used for naming saved image)
# imageSize: desired img size
#
def convertOGIntoSquare(imgName, inDir, outDir, imgNum, imageSize):
# load the image
img = imageSetting.load_img(imgName, inDir)
# get square image (array of pixels)
squareArray = getSquare.squareImage(img)[0]
sizeOfSquare = getSquare.squareImage(img)[1]
# get ratio between width and desired imageSize
widthRatio = sizeOfSquare / imageSize
# if it's not evenly divisable by imageSize, make it the next closest
# multiple of that number and then reduce
if not widthRatio.is_integer():
newSize = math.floor(widthRatio) * math.floor(imageSize)
squareArray = resizeSquare.resizeSquare(squareArray, newSize, sizeOfSquare)
sizeOfSquare = newSize
ratio = sizeOfSquare // math.floor(imageSize)
# new name for the new image
newImgName = outDir + "IM_" + format(imgNum, '04d') + "_REDUCED.jpg"
newImg = reduceImageSize.reduceImageSize(squareArray, ratio, sizeOfSquare)
# save reduced image
imageSetting.save_img(newImg, newImgName)
return newImgName