Completed
Branch external-img-dl (74a600)
by Anas
01:17
created

filt_Grayscale()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
1
import subprocess
2
3
4
# Cut & resize before processing
5
def cut_img(path):
6
    cut = "convert " + path + "original.jpg ( +clone +level-colors white \
7
           ( +clone -rotate 90 +level-colors black ) \
8
           -composite -bordercolor white -border 1 -trim +repage ) +swap -compose Src \
9
           -gravity center -composite -resize 612x612 " + path + "temp.jpg"
10
    subprocess.run(cut, shell=True)
11
12
13
# Add border of chosen color
14
def border(path, color):
15
    border = "convert  " + path + "temp.jpg -bordercolor " + color + " -border 20x20  " + path + "temp.jpg"
16
    subprocess.run(border, shell=True)
17
18
19
# Add frame
20
def frame(path, file):
21
    frame = "convert  " + path + "temp.jpg resources/frames/" + file + ".png -geometry +0+0 \
22
             -composite  " + path + "temp.jpg"
23
    subprocess.run(frame, shell=True)
24
25
26
# Vignette
27
def vignette(path, color1, color2):
28
    vignette = "convert " + path + "temp.jpg -size 918x918 radial-gradient:" + color1 + "-" + color2 + " \
29
                -gravity center -crop 612x612+0+0 +repage -compose multiply -flatten " + path + "temp.jpg"
30
    subprocess.run(vignette, shell=True)
31
32
33
# Resize (if modified) and rename
34
def finish(path, result_name):
35
    finish = "convert " + path + "temp.jpg -resize 612x612 " + path + result_name + ".jpg"
36
    subprocess.run(finish, shell=True)
37
38
39
# Filters to apply
40
def filt_Gotham(path):
41
    cut_img(path)
42
    primary_filter = "convert  " + path + "temp.jpg -modulate 120,10,100 -fill #222b6d \
43
              -colorize 20 -gamma 0.5 -contrast -contrast  " + path + "temp.jpg"
44
    subprocess.run(primary_filter, shell=True)
45
    border(path, "black")
46
    finish(path, "gotham")
47
48
49
def filt_Grayscale(path):
50
    cut_img(path)
51
    primary_filter = "convert  " + path + "temp.jpg -colorspace Gray " + path + "temp.jpg"
52
    subprocess.run(primary_filter, shell=True)
53
    finish(path, "grayscale")
54
55
56
def filt_Kelvin(path):
57
    cut_img(path)
58
    primary_filter = "convert " + path + "temp.jpg -auto-gamma -modulate 120,50,100 \
59
              -size 612x612 -fill rgba(255,153,0,0.5) -draw \"rectangle 0,0 612,612\" \
60
              -compose multiply " + path + "temp.jpg"
61
    subprocess.run(primary_filter, shell=True)
62
    frame(path, "kelvin")
63
    finish(path, "kelvin")
64
65
66
def filt_Lomo(path):
67
    cut_img(path)
68
    primary_filter = "convert " + path + "temp.jpg -channel R -level 25% \
69
             -channel G -level 25% " + path + "temp.jpg"
70
    subprocess.run(primary_filter, shell=True)
71
    vignette(path, "none", "black")
72
    finish(path, "lomo")
73
74
75
def filt_Nashville(path):
76
    cut_img(path)
77
    primary_filter = "convert  " + path + "temp.jpg -contrast -modulate 100,150,100 -auto-gamma " + path + "temp.jpg"
78
    subprocess.run(primary_filter, shell=True)
79
    color_overlay = "convert  " + path + "temp.jpg ( -clone 0 -fill #222b6d -colorize 100% ) \
80
                    ( -clone 0 -colorspace gray -negate ) -compose blend \
81
                    -define compose:args=50,50 -composite  " + path + "temp.jpg"
82
    subprocess.run(color_overlay, shell=True)
83
    color_overlay2 = "convert  " + path + "temp.jpg ( -clone 0 -fill #f7daae -colorize 100% ) \
84
                    ( -clone 0 -colorspace gray ) -compose blend \
85
                    -define compose:args=120,-20 -composite  " + path + "temp.jpg"
86
    subprocess.run(color_overlay2, shell=True)
87
    frame(path, "nashville")
88
    finish(path, "nashville")
89
90
91
def filt_Toaster(path):
92
    cut_img(path)
93
    color_overlay = "convert  " + path + "temp.jpg ( -clone 0 -fill #330000 -colorize 100% ) \
94
                    ( -clone 0 -colorspace gray -negate ) -compose blend \
95
                    -define compose:args=50,50 -composite  " + path + "temp.jpg"
96
    subprocess.run(color_overlay, shell=True)
97
    primary_filter = "convert  " + path + "temp.jpg -modulate 150,80,100 -gamma 1.2 -contrast -contrast " + path + "temp.jpg"
98
    subprocess.run(primary_filter, shell=True)
99
    vignette(path, "none", "LavenderBlush3")
100
    vignette(path, "#ff9966", "none")
101
    border(path, "white")
102
    finish(path, "toaster")
103
104
105
def filt_VHS(path):
106
    cut_img(path)
107
    red = "convert " + path + "temp.jpg -page +4+4 -background black -flatten -channel B -fx 0 " + path + "temp_r.jpg"
108
    subprocess.run(red, shell=True)
109
    green = "convert " + path + "temp.jpg -channel R -fx 0 " + path + "temp_g.jpg"
110
    subprocess.run(green, shell=True)
111
    blue = "convert " + path + "temp.jpg -page -4-4 -background black -flatten -channel G -fx 0 " + path + "temp_b.jpg"
112
    subprocess.run(blue, shell=True)
113
    combine = "convert " + path + "temp_r.jpg " + path + "temp_g.jpg " + path + "temp_b.jpg -average " + path + "temp.jpg"
114
    subprocess.run(combine, shell=True)
115
    frame(path, "scan")
116
    finish(path, "VHS")