-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursive_image.py
More file actions
executable file
·194 lines (167 loc) · 6.75 KB
/
recursive_image.py
File metadata and controls
executable file
·194 lines (167 loc) · 6.75 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#! /usr/bin/env python3
"""
Recursive Image generates a image using other images as pixels.
Copyright (C) 2020 Georg Manthey
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
version = 'Recursive Image v1.0'
from sys import argv, exit
from getopt import getopt, GetoptError
from make_image import make_image
#import antigravity
helptext = """
usage: {} -r <reference-image> -p <images-folder> -o <output-image>
This program generates a image using other images as pixels.
Arguments:
-h, --help
Prints out this text.
-o, --out
Specifies the output png-file.
-p, --img-path
The path containing the images used to make the reference image. This path should contain only images in png or jpg format.
-r, --ref-img
The image that is rebuilt with the other images.
-v, --version
Prints out the version of the program.
Other Arguments
--color-diff
The maximum difference allowed between the color of the reference image and the average color of the pixel image when randomly
assigning images.
--mini-height
The number of pixels one of the pixel-images is high.
--mini-width
The number of pixels one of the pixel-images is wide.
--out-height
The number of images that make up the height of the resulting pictures.
--out-width
The number of images that make up the width of the resulting pictures.
--ref-background
If 1, the color used for the background of the pixel-images is taken from the reference image, if 0, the average color of the
pixel-image is used as background.
--verbose
Makes program print status messages.
Notes
It is advised to give one of out_width/out_height and one of mini_width/mini_height, so that the overall size of the resulting
image can be specified, but the program can calculate the best fitting ratios.
If ref-background is False, color-diff should be kept relatively low, so that the reference image can still be identified.
30 seems to be a good value to still have some variation in the resulting images. If color-diff is very small, so that there
are no images available that are that close, a random image is taken from the best fitting 20 images.
If ref-background is True, color-diff may be chosen higher, so that there is a larger variation in the pixel-images. Then the
reference image will always be visible due to the background of the pixel-images.
The program might generate a lot of libpng warnings. This is not a problem, as long as the program keeps running.
Copyright
Copyright (C) 2020 Georg Manthey
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
""".format(argv[0])
wrong_argument = """
{} must be a positive Integer.
"""
args = argv[1:]
ref_img = ''
path = ''
out = ''
out_width = None
out_height = None
mini_width = None
mini_height = None
ref_background = False
color_diff = 30
verbose = False
if len(args) > 0:
try:
opts, args = getopt(args, 'hvr:p:o:', ['help', 'version', 'ref-img=', 'img-path=', 'out=', 'out-width=', 'out-height=', 'mini-widht=', 'mini-height=', 'ref-background=', 'color-diff=', 'verbose'])
except GetoptError:
print(helptext)
exit(2)
if len(args) > 0:
print('''arguments passed without option will be ignored:
{}
'''.format(args))
# read the parameters given
for opt, arg in opts:
if opt in ('-h', '--help'):
print(helptext)
exit()
if opt in ('-v', '--version'):
print(version)
exit()
if opt in ('-r', '--ref-img'):
ref_img = arg
if opt in ('-p', '--img-path'):
path = arg
if opt in ('-o', '--out'):
out = arg
if opt == '--out-width':
try:
out_width = int(arg)
except Exception:
out_width = -1
if out_width < 0:
print(wrong_argument.format('out-width'))
exit(2)
if opt == '--out-height':
try:
out_height = int(arg)
except Exception:
out_height = -1
if out_height < 0:
print(wrong_argument.format('out-height'))
exit(2)
if opt == '--mini-width':
try:
mini_width = int(arg)
except Exception:
mini_width = -1
if mini_width < 0:
print(wrong_argument.format('mini-width'))
exit(2)
if opt == '--mini-height':
try:
mini_height = int(arg)
except Exception:
mini_height = -1
if mini_height < 0:
print(wrong_argument.format('mini-height'))
exit(2)
if opt == '--ref-background':
if arg in ('False', 'false', 'F', 'f', '0'):
ref_background = False
elif arg in ('True', 'true', 'T', 't', '1'):
ref_background = True
else:
print('ref-background must be a boolean.')
exit(2)
if opt == '--color-diff':
try:
color_diff = float(arg)
except:
color_diff = -1
if color_diff < 0:
print('color-diff must be a positive number')
exit(2)
if opt == '--verbose':
verbose = True
if ref_img == "" or path == "" or out == "":
print(helptext)
exit(2)
make_image(path, ref_img, out, out_width, out_height, mini_width, mini_height, ref_background, color_diff, verbose)
else:
print(helptext)