-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.py
59 lines (52 loc) · 1.69 KB
/
functions.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Mariana, Matthew, and Alfredo
from PIL import Image
import os
def Grayscale(p):
image = p
im = Image.open(image)
if im.mode != 'RGB':
im = im.convert('RGB')
g_list = [(
int((p[0] * 299 + p[1] * 587 + p[2] * 114) // 1000),
int((p[0] * 299 + p[1] * 587 + p[2] * 114) // 1000),
int((p[0] * 299 + p[1] * 587 + p[2] * 114) // 1000)
) for p in im.getdata()]
im.putdata(g_list)
output_path = os.path.join("static/images", "grayscaleEdit.jpg")
im.save(output_path)
return output_path
def sepia(p):
if p[0] < 63:
r, g, b = int(p[0] * 1.1), p[1], int(p[2] * 0.9)
elif 63 <= p[0] <= 192:
r, g, b = int(p[0] * 1.15), p[1], int(p[2] * 0.85)
else:
r = int(p[0] * 1.08)
g, b = p[1], int(p[2] * 0.5)
return r, g, b
def Sepia(image_path):
im = Image.open(image_path)
if im.mode != 'RGB':
im = im.convert('RGB')
s_list = [sepia(pixel) for pixel in im.getdata()]
im.putdata(s_list)
output_path = os.path.join("static/images", "sepiaEdit.jpg")
im.save(output_path)
return output_path
def Negative(image_path):
im = Image.open(image_path)
if im.mode != 'RGB':
im = im.convert('RGB')
n_list = [(255 - p[0], 255 - p[1], 255 - p[2]) for p in im.getdata()]
im.putdata(n_list)
output_path = os.path.join("static/images", "NegativeEdit.jpg")
im.save(output_path)
return output_path
def Thumbnail(image_path):
im = Image.open(image_path)
if im.mode != 'RGB':
im = im.convert('RGB')
trgt = im.resize((252, 253))
output_path = os.path.join("static/images", "thumbnailEdit.jpg")
trgt.save(output_path)
return output_path