-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
128 lines (113 loc) · 4.29 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*- coding: utf-8 -*-
"""
Project: Automatic Collage Maker
Program by :
@author : Pranav Gundewar
"""
# Importing Libraries
from argparse import ArgumentParser
from image_process import ImageProcess
from collage_create import CollageCreation
import os
import random
from PIL import Image, ImageDraw, ImageFont
from os.path import isfile, isdir
from sys import exit
# from PIL.ExifTags import TAGS
import time
# import numpy as np
# import cv2
if __name__ == "__main__":
# Argument parsing
parser = ArgumentParser(description='Automatic Photo Collage Maker.')
parser.add_argument('-f', '--folder', dest='folder',
help='folder with images (*.jpg, *.jpeg, *.png)', default='.')
parser.add_argument('-o', '--output', dest='output',
help='path to the destination folder where images are to be saved')
parser.add_argument('-t', '--text', dest='text', type=str, action='store',
help='text that you want to display on final collages')
args = parser.parse_args()
# Run according to whether path is a file or a directory
if not args.folder:
print('Input directory is not provided. Current directory will be choosen for input image. ')
if not args.output:
print('Output directory is not provided. New directory with time-stamp will be created.')
timestr = time.strftime("%Y%m%d-%H%M%S")
filename = 'collage' + timestr
args.output = os.path.join(os.getcwd(), filename)
os.makedirs(args.output)
if not args.text:
print('Text not provided. Collages without any text will be created.')
# create an instance of defined class
process = CollageCreation(args.output, args.text)
if isfile(args.folder):
print('Please provide different directory containing at-least 2 images.. ')
exit(1)
elif isdir(args.folder):
count, images = process.processdir(args.folder)
print('Number of Input Images: ' + str(count))
# shuffle images if needed
random.shuffle(images)
# image_list = []
# list_hor = []
# list_ver = []
horizontal = []
vertical = []
# for img in images:
# ar = img.size[0] / img.size[1]
# if(ar > 1):
# list_hor.append(img)
# else:
# list_ver.append(img)
# # image_list.append(img)
# random.shuffle(image_list)
for img in images:
img.thumbnail((1200, 1200), Image.ANTIALIAS)
ar = img.size[0] / img.size[1]
if ar < 1:
vertical.append(img)
image1 = process.face_detection(img, 900, 600)
horizontal.append(image1)
else:
horizontal.append(img)
image2 = process.face_detection(img, 600, 900)
vertical.append(image2)
# shuffle images if needed
random.shuffle(images)
temp = images[0]
temp = process.face_detection(img, 900, 450)
# if(len(list_hor) > 2) and (len(list_ver) < 4):
# process.collage_2_hor(list_hor)
# process.collage_2_hor(list_hor)
# if (len(list_hor) < 2) and (len(list_ver) > 4):
# process.collage_4(list_ver)
# process.black_magic(list_ver)
# process.collage_4(list_ver)
# process.black_magic(list_ver)
# if (len(list_hor) > 2) and (len(list_ver) > 4):
# process.collage_3_hor(list_hor, list_ver)
# process.collage_3_hor(list_hor, list_ver)
# process.collage_4(list_ver)
# process.black_magic(list_ver)
# process.collage_4(list_ver)
# process.black_magic(list_ver)
# process.collage_2_hor(list_hor)
# process.collage_2_hor(list_hor)
process.collage_3_hor(horizontal, vertical)
process.collage_2_hor(horizontal)
process.collage_4(vertical)
process.black_magic(vertical)
process.portfolio(vertical, temp)
# res = process.make_collage(images, 1200, 450)
# if not res:
# print('Failed to create collage!')
# exit(1)
res = process.make_collage(images, 800, 300)
if not res:
print('Failed to create collage!')
exit(1)
# process.collage_3_hor(horizontal, vertical)
# process.collage_2_hor(horizontal)
# process.collage_4(vertical)
# process.black_magic(vertical)
print('All collages has been created. Head over to the output directory...')