forked from Nevt12/xshot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
xshot.sh
executable file
·436 lines (413 loc) · 11.8 KB
/
xshot.sh
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#!/usr/bin/env bash
# xshot automatic screenshots
# coded by D_baj
# recode by AzRycb
# xshot 1.0.4 Remake
# color
o='\033[0m'
r='\033[1;31m'
b='\033[1;36m'
bx='\033[2;7;36m'
w='\033[1;37m'
y='\033[1;33m'
g='\033[1;32m'
#hex color
hex_color=(
"#3d465c" #dark
"#1E222B" #dark2
"#F8F9FA" #light
"#000000" #black
"fffffff" #white
"#59d6ff" #blue
"#e6e6e6" #gray
"#38d13e" #green
)
# other
N=$r'['$y'~'$r']'
P=$r'['$y'?'$r'] '
W=$r'['$r'!'$r'] '
F=$r'['$r'x'$r'] '
S=$r'['$g'✓'$r'] '
I=$r'['$r'*'$r'] '
B=$r'['$y'+'$r'] '
# path
camera_path="/sdcard/DCIM/Camera"
screenshots_path="/sdcard/DCIM/screenshots"
camera_backup="${camera_path}/backup"
screenshots_backup="${screenshots_path}/backup"
manual_backup="/sdcard/DCIM/backup"
# style
#titlebar
convert_titlebar="yes"
add_on_img=""
width_img=500
height_img=1000
#border
border_size=50
border_radius=10
border_c_dark="${hex_color[0]}"
border_c_light="${hex_color[2]}"
# shadow
shadow_size="85x10+0+10"
shadow_color="${hex_color[3]}"
# footer text
owner_info=" @AzRyCb"
footer_text=" Enhanced Screenshots Using Xshot"
#footer style
#xshot
footer_xy="+0+30"
footer_xy_time="+0+20"
footer_size=20
footer_size_time=15
footer_color="${hex_color[3]}"
#timeStamp
footer_xy_timeStamp2="+50+50"
footer_xy_timeStamp="+50+200"
footer_size_timeStamp=55
footer_color_timeStamp="${hex_color[5]}"
footer_color_timeStamp2="${hex_color[6]}"
#other
count=1
check_format=(
"${g}Done"
"${r}Failed"
"${g}Done"
"${r}Failed"
)
if [[ ${type} = "MANUAL SHOT" ]]; then
check_s=${check_format[2]}
check_f=${check_format[3]}
else
check_s=${check_format[0]}
check_f=${check_format[1]}
fi
backup="yes" #default yes
#create backup
if [[ ! -d ${screenshots_backup} ]]; then
mkdir "${screenshots_backup}"
elif [[ ! -d ${camera_backup} ]]; then
mkdir "${camera_backup}"
elif [[ ! -d "${manual_backup}" ]]; then
mkdir "${manual_backup}"
fi
light () {
color="LIGHT"
titlebar_color=${hex_color[1]}
border_color=${border_c_light}
}
dark () {
color="DARK"
titlebar_color=${hex_color[1]}
border_color=${border_c_dark}
}
backup ()
{
renamed=$(echo $file_name | sed "s/.jpg/_backup.jpg/g")
chmod +x "${file}"
cp "${file}" "${path_backup}/${renamed}"
}
log () {
echo -e "${r}[${y}$(date +'%H:%M:%S')${r}]${o} $@"
}
prompt(){
echo -e "$(log)${b}Please input file : ${y}"
}
check() {
if [[ $? -eq 0 && ${PIPESTATUS[0]} -eq 0 ]]; then
echo -e " $(log)${check_s}"
else
echo -e " $(log)${check_f}"
exit 1
fi
}
count() {
echo -e "${r}[${y}$((${count} + 1 ))${r}]${o}"
}
header() {
echo -e "
${r} ╔═══════════════════════════════╗
║ ╔═╗╔═╦═══╦╗ ╔╦═══╦════╗ ║
║ ╚╗╚╝╔╣╔═╗║║ ║║╔═╗║╔╗╔╗║ ║
║ ╚╗╔╝║╚══╣╚═╝║║ ║╠╝║║╚╝ ║
║ ╔╝╚╗╚══╗║╔═╗║║ ║║ ║║ ║
║ ╔╝╔╗╚╣╚═╝║║ ║║╚═╝║ ║║ ║
║ ╚═╝╚═╩═══╩╝ ╚╩═══╝ ╚╝ ║
║ ${b}V1.0.4${r} ║
║ screenshot tools${r} ║
╚═══════════════════════════════╝
╔═══════════════════════════════╗
║ ${y} EXECUTE${r} ║
╔═════════╩═══════════════════════════════╩═════════╗
╚═══════════════════════════════════════════════════╝
╔════════════════════╗ ╔════════════════════╗
║ ${y}TYPE : ${b}${type}${space1}${y}THEME : ${b}${color}${space2}
╚════════════════════╝ ╚════════════════════╝
press ctrl + c for close"
}
help() {
echo -e "${y}
Usage :
bash xshot.sh [options1] [options2] [options3]
options 1:
-h Show help display
-i show program information
-a autoshot (run automatic detect new file)
-m manual input file
-wm automatic add wateemark to your image capture
options 2:
-l light theme
-d dark theme
options 3:
-! run autoshot without footer text
examples:
bash xshot.sh -a -l
bash xshot.sh -a -l -!
or
bash xshot.sh -a -d (default)
"
}
program_info(){
echo -e "${r}
╔═══════════════════════════════╗
║ ╔═╗╔═╦═══╦╗ ╔╦═══╦════╗ ║
║ ╚╗╚╝╔╣╔═╗║║ ║║╔═╗║╔╗╔╗║ ║
║ ╚╗╔╝║╚══╣╚═╝║║ ║╠╝║║╚╝ ║
║ ╔╝╚╗╚══╗║╔═╗║║ ║║ ║║ ║
║ ╔╝╔╗╚╣╚═╝║║ ║║╚═╝║ ║║ ║
║ ╚═╝╚═╩═══╩╝ ╚╩═══╝ ╚╝ ║
║ ${b}V1.0.4${r} ║
║ screenshot tools${r} ║
╚═══════════════════════════════╝
${b}
A tool to make your screenshots look better
Owner : D_4J
Remake : AzRycb
Build date : 05/05/2022"
}
autoshot() {
clear
header
echo -e " ${r}[${y}${count}${r}]"
echo -e " $(log)${b}Waiting new file"
inotifywait -m -e create $path 2> /dev/null | \
while read filename; do
main
done
}
manual() {
clear
header
read -p " $(prompt)" file_name
echo -e " $(log)${b}find file ${y}${file_name}${b} in path ${y}/sdcard"
cd /sdcard
if [[ $? -eq 0 && ${PIPESTATUS[0]} -eq 0 ]]; then
result=$(find -name "${file_name}" | sed 's .\{2\} ')
if [[ ${result} = "" ]]; then
echo -e " $(log)${r}file not found, please check again !"
exit 1
fi
echo -e " $(log)${b}found file in ${y}/sdcard/${result}"
file="/sdcard/${result}"
echo -e " $(log)${b}converting file ..."
titlebar
ss
else
echo -e " $(log)${r}permission denied, please run ${y}termux-setup-storage"
fi
}
main(){
file_name=$(echo -e "${filename}" | awk '{print $3}')
file=${path}/${file_name}
echo -e " $(log)${b}Find file"
echo -e " $(log)${b}Found file ${y}${file_name}"
if [[ ${run} = "auto" ]]; then
if [[ $backup = "yes" ]]; then
echo -e " $(log)${b}Backup file"
backup
fi
echo -e " $(log)${b}Converting"
titlebar
ss
elif [[ ${run} = "wm" ]]; then
echo -e " $(log)${b}Converting"
timeStamp
fi
}
titlebar(){
# width_img=$(magick ${file} - format "%w" info:)
# height_img=$(magick ${file} - format "%h" info:)
# if (( ${width_img} > ${height_img} )); then
# height_img=${width_img}
# elif (( ${width_img} < ${height_img} )); then
# width_img=${height_img}
# fi
# function coded by arman
gr="#27C93F" #green
yl="#FFBD2E" #yellow
rd="#FF5F56" #red
bl="#282C34" #black
rad=$( echo "0.0025 * ${width_img} * ${height_img} / 100" | bc )
br=$( echo "${rad} * 5" | bc )
x0=$( echo "${rad} * 3" | bc )
y0=$( echo "${br} * 0.5" | bc )
x1=$( echo "${x0} + ${rad}" | bc )
declare -A arr=()
for i in {0..2}; do
arr[$i,0]=$x0
arr[$i,1]=$y0
arr[$i,2]=$x1
arr[$i,3]=$y0
x0=$( echo "${x0} + ${rad} * 3" | bc )
x1=$( echo "${x0} + ${rad}" | bc)
done
#1520x720
#760x360
if [[ "${add_on_img}" == "yes" ]]; then
magick "$" -fill $bl \
-bar ${codebold} \ ${title}
-background ${titlebar_color} \
-gravity north \
-chop 0x$br \
-splice 0x$br \
-draw "fill ${rd} circle ${arr[0,0]},${arr[0,1]} ${arr[0,2]},${arr[0,3]}
fill ${yl} circle ${arr[1,0]},${arr[1,1]} ${arr[1,2]},${arr[1,3]}
fill ${gr} circle ${arr[2,0]},${arr[2,1]} ${arr[2,2]},${arr[2,3]}" \
$file
else
magick $file -fill $bl \
-background ${titlebar_color} \
-gravity north -splice 0x$br\
-draw "fill ${rd} circle ${arr[0,0]},${arr[0,1]} ${arr[0,2]},${arr[0,3]}
fill ${yl} circle ${arr[1,0]},${arr[1,1]} ${arr[1,2]},${arr[1,3]}
fill ${gr} circle ${arr[2,0]},${arr[2,1]} ${arr[2,2]},${arr[2,3]}" \
$file
fi
}
ss() {
footer_time=" $(date +'%a %d.%h.%Y') $(date +'%H:%M')"
magick "$file" \
-alpha set -virtual-pixel transparent \
-channel A -blur 0x5 -threshold 50% +channel \
\( +clone -background "${shadow_color}" \
-shadow ${shadow_size} \) \
+swap -background none -layers merge +repage \
-bordercolor "${border_color}" -border ${border_size} \
"$file"
if [[ ${wm} = "no" ]]; then
#nowm
check
if [[ $type = "MANUAL SHOT" ]]; then
echo -e " $(log)${g}${file}${r}"
else
echo -e " ${r}[ ${g}${file}${r} ]"
count=$(( ${count} + 1 ))
echo -e " ${r}[${y}${count}${r}]"
echo -e " $(log)${b}Waiting new file"
fi
else
magick "$file" \
-gravity South -background none \
-font JetBrains-Mono-Medium-Nerd-Font-Complete \
-pointsize ${footer_size} \
-fill ${footer_color} \
-annotate ${footer_xy} "${footer_text}" \
-gravity North -background none \
-pointsize ${footer_size_time} \
-annotate ${footer_xy_time} "${footer_time}" \
"$file"
check
if [[ $type = "MANUAL SHOT" ]]; then
echo -e " $(log)${g}${file}${r}"
else
echo -e " ${r}[ ${g}${file}${r} ]"
count=$(( ${count} + 1 ))
echo -e " ${r}[${y}${count}${r}]"
echo -e " $(log)${b}Waiting new file"
fi
fi
}
timeStamp() {
owner_info=" @D_4J"
owner_info2=" $(date +'%H:%M')
$(date +'%a %d.%h.%Y')"
magick "${file}" \
-gravity SouthWest -background black \
-font JetBrains-Mono-Medium-Nerd-Font-Complete \
-pointsize $footer_size_timeStamp \
-fill $footer_color_timeStamp \
-annotate $footer_xy_timeStamp "${owner_info}" \
-fill $footer_color_timeStamp2 \
-annotate $footer_xy_timeStamp2 "${owner_info2}" \
"${file}"
check
echo -e " ${r}[ ${g}${file}${r} ]"
count=$(( ${count} + 1 ))
echo -e " ${r}[${y}${count}${r}]"
echo -e " $(log)${b}Waiting new file"
}
if [[ $3 = "-!" ]]; then
wm="no"
elif [[ $4 = "" ]]; then
input="yes"
fi
case "$1" in
-a )
type="AUTOSHOT"
space1="${r} ║ ║ "
path=${screenshots_path}
path_backup=${screenshots_backup}
run="auto"
case "$2" in
-l )
space2="${r} ║"
light
autoshot
;;
-d)
space2="${r} ║"
dark
autoshot
;;
* )
help
;;
esac
;;
-m )
type="MANUAL SHOT"
path=${FILE}
space1="${r} ║ ║ "
run="manual"
case "$2" in
-l )
light
space2="${r} ║"
manual
;;
-d )
dark
space2="${r} ║"
manual
;;
* )
help
;;
esac
;;
-wm )
type="TIME STAMP"
path=${camera_path}
path_backup=${camera_backup}
space1="${r} ║ ║ "
color="none"
space2="${r} ║"
run="wm"
autoshot
;;
-i )
program_info
;;
* )
help
;;
esac