-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decal-Converter.sh
938 lines (733 loc) · 42.7 KB
/
Decal-Converter.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
#!/usr/bin/env bash
################################################################################################
# Decal converter by Ed Houseman jr - Created 10/27/22 #
################################################################################################
# This script relies on Imagemagick, Pngquant and Zenity installed on a Unix system #
################################################################################################
# Photos MUST be in .png format, and have a transparent background #
################################################################################################
# Options include: Convert to PNG, Convert to GIF, Colorize, Fill visible color with black #
################################################################################################
# This generate new photos of decals, in a new folder (from white or black) to the colors of: #
# #######################################################################
# Colors are: #
# *White - #ffffff #
# *Black - #000000 #
# *Blue - #1791d8 #
# *Teal - #29bbc8 #
# *Red - #a01922 #
# *Green - #008c35 #
# *Silver - #928F98 #
# *Pink - #FFADE5 #
# *Purple = #1a0e67 #
# *Dark-Blue = #003478 #
# *Orange = #d56f31 #
# *Yellow = #f3e11f #
# *Neon-Green = ##39FF14 #
##########################
##############################
##### Define directories #####
##############################
# Main decal directory
decals="${HOME}/Decals"
# Original Decal backup folder
original_dir="${HOME}/Decals/Original"
# Colorized folder
colorized_dir="${HOME}/Decals/Colorized"
# Converted to png folder
png_converted_dir="${HOME}/Decals/PNG"
# Color fill folder
black_fill_dir="${HOME}/Decals/Black-Fill"
# GIF folder
gif_dir="${HOME}/Decals/GIF"
# Tablet images for slideshow folder
tablet_dir="${HOME}/Decals/Tablet"
##########################
##### Define options #####
##########################
# Convert decal to PNG
opt1="Convert To PNG"
# Convert decal to GIF
opt2="Convert To GIF"
# Colorize decal
opt3="Colorize Decals"
# Replace all visible color in decal to black
opt4="Fill All Visible Color With Black"
# single conversion
opt5="Single Conversion"
# Multiple conversion
opt6="Multiple Conversion"
# Create tablet images
opt7="Create Tablet Images"
#####################
##### Functions #####
#####################
#############################################
# Create function for single png conversion #
#############################################
png_conversion_single () {
# Select the single decal file to be converted to png format
input_file=$(zenity --file-selection --title="Select the source decal")
# If the user selects the "cancel" button, close the script
if [[ "$?" == "1" ]]; then
exit
fi
# Remove path and extension from input directory
input_file_stripped=$(basename "${input_file%.*}")
# Check if file already exists in PNG folder
if [[ -f "${png_converted_dir}/${input_file_stripped}.png" ]]; then
zenity --error --title="File already exists" --text="The selected file ( ${input_file_stripped}.png ) already exist\n\nPlease check and/or rename file, and try again" --width=400 --height=100
# Restart function "png_conversion_single"
png_conversion_single
fi
# Copy original file to "Original" folder (backup)
cp "$input_file" "$original_dir"
# Convert the single decal file to png format, and save in png folder
convert "$input_file" "${png_converted_dir}/${input_file_stripped}.png"
}
###############################################
# Create function for multiple png conversion #
###############################################
png_conversion_multiple () {
# Select the input folder
input_dir=$(zenity --file-selection --directory --filename="Desktop" --title="Select a directory" --text="Select the directory with your decals\nthat need to be converted to png")
# If the user selects the "cancel" button, close the script
if [[ "$?" == "1" ]]; then
exit
fi
# Count number of decal files
total_files=$(ls "$input_dir" 2> /dev/null | wc -l)
# Get number to increment progress bar by
increment=$(echo "scale=2; 100/${total_files}" | bc)
# Set initial percentage
percentage="0"
# Set current decal number in loop
current_decal_number="0"
# Start looping through folder
for decal in "${input_dir}"/* ; do
# Copy original file to "Original" folder (backup)
cp "$decal" "$original_dir"
# Set value for current decal in loop
((current_decal_number++))
# Remove path and extension from input directory
input_file_stripped=$(basename "${decal%.*}")
# Check if file already exists in PNG folder
if [[ ! -f "${decal}.png" ]]; then
# Convert the single decal file to png format, and save in png folder
convert "$decal" "${png_converted_dir}/{$input_file_stripped}.png" 2>/dev/null
fi
# increment percentage number
percentage=$(echo "${percentage}+${increment}" | bc)
# Echo percentage number to zenity progress
echo "0${percentage}" ; sleep 0.2
# remove path for zenity progress
decal_basename=$(basename "${decal%.*}")
# Echo text for zenity progress
echo "# Creating: ${decal_basename}.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} \( ${decal_basename} \)\n" ; sleep 0.2
done
}
#############################################################
# Create function for generating a gif image (single image) #
#############################################################
gif_conversion_single () {
# Select the input folder
dir_input=$(zenity --file-selection --directory --filename="${HOME}/Decals/Colorized")
# If the user selects the "cancel" button, close the script
if [[ "$?" == "1" ]]; then
exit
fi
# Directory where the gif folders are saved
dir_output="${HOME}/Decals/GIF"
# Get folder name
folder_name=$(basename "${dir_input}")
# Convert decal to gif (if it doesn't exist)
if [[ ! -f "${dir_input}.gif" ]]; then
convert -dispose previous -delay 100 -loop 0 "${dir_input}/*.png" "${gif_dir}/${folder_name}.gif" 2>/dev/null
fi
}
#######################################################################################
# Create function for generating gif images from "Colorized" folder (multiple images) #
#######################################################################################
# Create a function for gif generation from "Colorized" folder
gif_conversion_multiple () {
# Directory where the decal folders are
dir_input="${HOME}/Decals/Colorized"
# Directory where the gif folders are saved
dir_output="${HOME}/Decals/GIF"
# Count number of decal folders
total_folders=$(find "$dir_input" -mindepth 1 -maxdepth 1 -type d 2> /dev/null | wc -l)
# error box if Decals/Colorized is empty
if [[ "$total_folders" == "0" ]]; then
zenity --error --title="Colorized folder is empty!" --text="Your \"Colorized\" folder is empty\n\nPlease add folders to ${HOME}/Decals/Colorized to continue" --width="400" --height="100"
fi
# Get number to increment progress bar by
increment=$(echo "scale=2; 100/${total_folders}" | bc)
# Set initial percentage
percentage="0"
# Set current decal number in loop
current_decal_number="0"
# Create loop
for decal in "${HOME}/Decals/Colorized"/* ; do
# Set value for current decal in loop
((current_decal_number++))
# remove path for zenity progress
decal_basename=$(basename "${decal%.*}")
# Convert decal to gif (if it doesn't exist)
if [[ ! -f "${decal}.gif" ]]; then
convert -dispose previous -delay 100 -loop 0 "${decal}/*.png" "${dir_output}/${decal_basename}.gif" 2>/dev/null
fi
# increment percentage number
percentage=$(echo "${percentage}+${increment}" | bc)
# Echo percentage number to zenity progress
echo "0${percentage}" ; sleep 0.2
# Echo text for zenity progress
echo "# Creating: ${decal_basename}.gif \n\nCurrent Decal: ${current_decal_number} of ${total_folders} \( ${decal_basename} \)"; sleep 0.2
done
}
##################################################################################
# Create function for generating color decals and compressing png (single image) #
##################################################################################
colorize_single () {
# The input or "source" .png file
input_file=$(zenity --file-selection --title="Select the source decal")
# If the user selects the "cancel" button, close the script
if [[ "$?" == "1" ]]; then
exit
fi
# Remove path from variable "input_file"
input_file_no_path=$(basename "$input_file")
# Remove path and extension from variable "input_file"
input_file_stripped=$(basename "${input_file%.*}")
# If the file name is not .png
if [[ "$input_file" != *.png ]]; then
# Error box stating the selected file is not a .png file
zenity --error --text="The selected file ( ${input_file_no_path} ) is not a png file\n\nPlease try again" --width=400 --height=100
# Restart "colorize_single" function
colorize_single
fi
# Check if image is transparent
transparency_check=$(identify -format %A "$input_file")
# If the file contains no transparency
if [[ "$transparency_check" == "False" ]]; then
# Error box stating the selected file has no transparency
zenity --error --text="The selected file ( ${input_file_no_path} ) contains no transparency\n\nPlease try again" --width=400 --height=100
# Restart colorize_single function
colorize_single
fi
# If the directory doesn't exist
if [[ ! -d "${colorized_dir}/${input_file_stripped}" ]]; then
# Copy original image to original folder
cp "$input_file" "$original_dir"
# Create directory from decal name
mkdir -p "${colorized_dir}/${input_file_stripped}"
fi
# Set initial percentage
percentage="0"
# Set increment value
increment="3.807692308"
# Create and compress white image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-White.png\n" ; sleep 0.2
convert "$input_file" -fill "#ffffff" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-White.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-White.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-White.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-White.png"
# Create and compress black image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Black.png\n" ; sleep 0.2
convert "$input_file" -fill "#000000" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Black.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Black.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Black.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Black.png"
# Create and compress Blue image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Blue.png\n" ; sleep 0.2
convert "$input_file" -fill "#1791d8" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Blue.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Blue.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Blue.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Blue.png"
# Create and compress Teal image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Teal.png\n" ; sleep 0.2
convert "$input_file" -fill "#29bbc8" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Teal.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Teal.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Teal.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Teal.png"
# Create and compress Red image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Red.png\n" ; sleep 0.2
convert "$input_file" -fill "#a01922" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Red.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Red.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Red.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Red.png"
# Create and compress Green image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Green.png\n" ; sleep 0.2
convert "$input_file" -fill "#008c35" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Green.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Green.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Green.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Green.png"
# Create and compress Silver image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Silver.png\n" ; sleep 0.2
convert "$input_file" -fill "#928F98" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Silver.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Silver.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Silver.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Silver.png"
# Create and compress Pink image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Pink.png\n" ; sleep 0.2
convert "$input_file" -fill "#FFADE5" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Pink.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Pink.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Pink.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Pink.png"
# Create and compress purple image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Purple.png\n" ; sleep 0.2
convert "$input_file" -fill "#452167" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Purple.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Purple.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Purple.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Purple.png"
# Create and compress Dark-Blue image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Dark-Blue.png\n" ; sleep 0.2
convert "$input_file" -fill "#003478" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Dark-Blue.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Dark-Blue\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Dark-Blue.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Dark-Blue.png"
# Create and compress Orange image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Orange.png\n" ; sleep 0.2
convert "$input_file" -fill "#d56f31" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Orange.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Orange.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Orange.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Orange.png"
# Create and compress Yellow image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Yellow.png\n" ; sleep 0.2
convert "$input_file" -fill "#f3e11f" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Yellow.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Yellow.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Yellow.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Yellow.png"
# Create and compress Neon-Green image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Neon-Green.png\n" ; sleep 0.2
convert "$input_file" -fill "#39FF14" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Neon-Green.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Neon-Green.png\n" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Neon-Green.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Neon-Green.png"
echo "100" ; sleep 0.2
echo "# Finished Creating Decal Images"; sleep 0.2
}
################################################################################################
# Create function for generating color decals and compressing png (multiple images) #
################################################################################################
colorize_multiple () {
# The input or "source" .png file
input_dir=$(zenity --file-selection --directory --filename="Desktop" --title="Select a directory")
# If the user selects the "cancel" button, close the script
if [[ "$?" == "1" ]]; then
exit
fi
# Set initial percentage
percentage="0"
# get total number of files in input folder
total_files=$(ls "$input_dir" 2> /dev/null | wc -l)
# Multiply total_files variable x 27 (27 processes performed)
tasks=$(echo "${total_files}*26" | bc)
# Get number to increment progress bar by
increment=$(echo "scale=8; 100/${tasks}" | bc)
# Set current decal number in loop
current_decal_number=0
# Start looping through folder
for decal in "${input_dir}"/* ; do
# Remove path and extension from input directory
input_file_no_path=$(basename "$decal")
input_file_stripped=$(basename "${decal%.*}")
# remove path for zenity progress
decal_basename=$(basename "${decal%.*}")
# Set value for current decal in loop
((current_decal_number++))
# Get progress percentage for total process
if [[ "${percentage%.*}" == "0" ]]; then
total_percentage="Calculating Progress..."
else total_percentage="${percentage%.*}% Total Progress"
fi
# Check if image is transparent
transparency_check=$(identify -format %A "$decal")
# If the file contains no transparency
if [[ "$transparency_check" == "True" ]] && [[ ! -d "${colorized_dir}/${input_file_stripped}" ]]; then
# Copy original image to original folder
cp "$decal" "$original_dir"
mkdir -p "${colorized_dir}/${input_file_stripped}"
# Create and compress white image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-White.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#ffffff" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-White.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-White.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-White.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-White.png"
# Create and compress black image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Black.png \n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#000000" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Black.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Black.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Black.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Black.png"
# Create and compress Blue image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Blue.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#1791d8" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Blue.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Blue.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Blue.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Blue.png"
# Create and compress Teal image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Teal.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#29bbc8" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Teal.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Teal.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Teal.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Teal.png"
# Create and compress Red image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Red.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#a01922" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Red.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Red.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Red.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Red.png"
# Create and compress Green image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Green.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#008c35" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Green.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Green.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Green.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Green.png"
# Create and compress Silver image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Silver.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#928F98" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Silver.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Silver.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Silver.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Silver.png"
# Create and compress Pink image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Pink.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#FFADE5" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Pink.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Pink.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Pink.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Pink.png"
# Create and compress Purple image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Purple.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#452167" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Purple.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Purple.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Purple.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Purple.png"
# Create and compress Dark-Blue image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Dark-Blue.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#003478" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Dark-Blue.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Dark-Blue.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Dark-Blue.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Dark-Blue.png"
# Create and compress Orange image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Orange.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#d56f31" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Orange.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Orange.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Orange.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Orange.png"
# Create and compress Yellow image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Yellow.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#f3e11f" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Yellow.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Yellow.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Yellow.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Yellow.png"
# Create and compress Neon-Green image
# Creating
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Creating: ${input_file_stripped}-Neon-Green.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
convert "$decal" -fill "#39FF14" -colorize "100" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Neon-Green.png"
# Compressing
percentage=$(echo "scale=2; ${percentage}+${increment}" | bc)
echo "0${percentage}" ; sleep 0.2
echo "# Compressing: ${input_file_stripped}-Neon-Green.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} ( ${input_file_stripped} )\n\n $total_percentage" ; sleep 0.2
pngquant --force --quality=40-100 --strip --skip-if-larger --verbose --output "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Neon-Green.png" "${colorized_dir}/${input_file_stripped}/${input_file_stripped}-Neon-Green.png"
fi
done
}
#####################################################################
# Create function for filling all visible color with black (single) #
#####################################################################
black_fill_single() {
# The input or "source" .png file
input_file=$(zenity --file-selection --title="Select the source decal")
# If the user selects the "cancel" button, close the script
if [[ "$?" == "1" ]]; then
exit
fi
# Remove path from variable "input_file"
input_file_no_path=$(basename "$input_file")
# Remove extension from variable "input_file_no_path
input_file_stripped=${input_file_no_path%.*}
# If the file name is not .png
if [[ "$input_file" != *.png ]]; then
# Error box stating the selected file is not a .png file
zenity --error --text="The selected file \"$(basename "$input_file")\" is not a png file \n \n Please try again" --width=400 --height=100
# Restart "black_fill_single" function
black_fill_single
fi
# Check if image is transparent
transparency_check=$(identify -format %A "$input_file")
# If the file contains no transparency
if [[ "$transparency_check" == "False" ]]; then
# Error box stating the selected file has no transparency
zenity --error --text="The selected file \"$(basename "$input_file")\" contains no transparency \n \n Please try again" --width="400" --height="100"
# Restart "black_fill_single" function
black_fill_single
fi
# If the directory doesn't exist
if [[ ! -d "${black_fill_dir}/${input_file_stripped}" ]]; then
# Copy original image to original folder
cp "$input_file" "$original_dir"
# Create directory for black fill
#mkdir -p "${black_fill_dir}/${input_file_stripped}"
# Fill png with black, and add to Black-Fill"" directory
convert "$input_file" -fill "#000000" -colorize "100" "${black_fill_dir}/${input_file_no_path}"
fi
}
#######################################################################
# Create function for filling all visible color with black (multiple) #
#######################################################################
black_fill_multiple() {
# The input or "source" .png folder
input_dir=$(zenity --file-selection --directory --filename="Desktop" --title="Select a directory")
# If the user selects the "cancel" button, close the script
if [[ "$?" == "1" ]]; then
exit
fi
# Count number of decal files
total_files=$(ls "$input_dir" 2> /dev/null | wc -l)
# Get number to increment progress bar by
increment=$(echo "scale=2; 100/${total_files}" | bc)
# Set initial percentage
percentage="0"
# Set current decal number in loop
current_decal_number="0"
# Start looping through folder
for decal in "${input_dir}"/* ; do
# Copy original file to "Original" folder (backup)
cp "$decal" "$original_dir"
# Set value for current decal in loop
((current_decal_number++))
# Remove path and extension from input directory
input_file_stripped=$(basename "${decal%.*}")
# Check if file already exists in PNG folder
if [[ ! -f "${black_fill_dir}/${decal}.png" ]]; then
# Fill png with black, and add to Black-Fill"" directory
convert "$decal" -fill "#000000" -colorize "100" "${black_fill_dir}/${input_file_stripped}.png"
fi
# increment percentage number
percentage=$(echo "${percentage}+${increment}" | bc)
# Echo percentage number to zenity progress
echo "0${percentage}" ; sleep 0.2
# remove path for zenity progress
decal_basename=$(basename "${decal%.*}")
# Echo text for zenity progress
echo "# Creating: ${input_file_stripped}.png\n\nCurrent Decal: ${current_decal_number} of ${total_files} \( ${decal_basename} \)\n" ; sleep 0.2
done
}
#################################################################################
# Create function for tablet image creation for slideshow from colorized folder #
#################################################################################
create_tablet_images () {
# see if Tablet folder exists, and create if it doesn't exist
if [[ ! -d "tablet_dir" ]]; then
mkdir -p $tablet_dir
fi
for decal in "${colorized_dir}"/*/*.png ; do
decal_basename=$(basename "${decal}")
if [[ ! -f "${tablet_dir}/${decal_basename}" ]]; then
composite "$decal" "/usr/share/decal-converter/bg-tablet.png" -gravity Center -quality 95 "${tablet_dir}/${decal_basename}"
fi
done | zenity --progress --pulsate --width=400 --height=100 --auto-close --title="Creating Images For Tablet Slideshow"
}
#######################
##### MAIN SCRIPT #####
#######################
# See if "Decals" folder exists, and create if it doesn't
if [[ ! -d "${HOME}/Decals" ]]; then
zenity --info --title="Decals folder does not exist" --text="Since this is the first time running Decal Converter\n\n \* A \"Decals\" folder will be created in your home directory\n\n \* \"Decals\" will be added to your bookmarks" --width="500"
# if user selects cancel then exit
if [[ "$?" == "1" ]]; then
exit
fi
# Make directory "Decals" if it doesn't exist
mkdir -p $decals
mkdir -p $original_dir
mkdir -p $colorized_dir
mkdir -p $png_converted_dir
mkdir -p $black_fill_dir
mkdir -p $gif_dir
mkdir -p $tablet_dir
# Change bookmark breakpoints from default 10 - 15
dconf write /org/nemo/window-state/sidebar-bookmark-breakpoint 15
# Add "Decals" folder to bookmarks
echo "file://${HOME}/Decals Decals" >> "${HOME}/.config/gtk-3.0/bookmarks"
fi
##################
# Define Actions #
##################
# ask user which task they would like to perform
action1=$(zenity --list --title="What would you like to do?" --text="Please select an option" --column="Select" --column="Task to perform" FALSE "$opt1" FALSE "$opt2" FALSE "$opt3" FALSE "$opt4" FALSE "$opt7" --radiolist --width=350 --height=250)
if [[ "$?" == "1" ]]; then
exit
fi
if [[ "$action1" == "$opt7" ]]; then
create_tablet_images
zenity --question --title="Do you have more decals?" --text="Would you like to Exit or Continue?" --ok-label="Continue" --cancel-label="Exit" --width="400" --height="100"
if [[ "$?" == "0" ]]; then
exec "$0"
elif [[ "$?" == "1" ]]; then
exit
fi
fi
# ask user if single or multiple files
action2=$(zenity --list --title="do you have a single file or multiple files?" --text="Please select an option" --column="Select" --column="Task to perform" FALSE "$opt5" FALSE "$opt6" --radiolist --width=350 --height=175)
if [[ "$?" == "1" ]]; then
exit
fi
# Single png conversion
if [[ "$action1" == "$opt1" ]] && [[ "$action2" == "$opt5" ]]; then
png_conversion_single
# Multiple png conversion
elif [[ "$action1" == "$opt1" ]] && [[ "$action2" == "$opt6" ]]; then
png_conversion_multiple | zenity --progress --auto-close --auto-kill --width="500" --height="100" --title="Creating PNG images"
# Single gif conversion
elif [[ "$action1" == "$opt2" ]] && [[ "$action2" == "$opt5" ]]; then
gif_conversion_single
# Multiple gif conversion
elif [[ "$action1" == "$opt2" ]] && [[ "$action2" == "$opt6" ]]; then
gif_conversion_multiple | zenity --progress --auto-close --auto-kill --width="500" --title="Creating GIF images"
# Single colorize conversion
elif [[ "$action1" == "$opt3" ]] && [[ "$action2" == "$opt5" ]]; then
colorize_single | zenity --progress --auto-close --auto-kill --width="500" --height="100" --title="Creating Decal Images"
# Multiple colorize conversion
elif [[ "$action1" == "$opt3" ]] && [[ "$action2" == "$opt6" ]]; then
colorize_multiple | zenity --progress --auto-close --auto-kill --width="500" --height="100" --title="Creating Decal Images"
# Single black fill conversion
elif [[ "$action1" == "$opt4" ]] && [[ "$action2" == "$opt5" ]]; then
black_fill_single
# Multiple black fill conversion
elif [[ "$action1" == "$opt4" ]] && [[ "$action2" == "$opt6" ]]; then
black_fill_multiple | zenity --progress --auto-close --auto-kill --width="500" --height="100" --title="Filling Decal Color With Black"
fi
# Ask user if they have more decals to do
zenity --question --title="Do you have more decals?" --text="Would you like to Exit or Continue?" --ok-label="Continue" --cancel-label="Exit" --width="400" --height="100"
if [[ "$?" == "0" ]]; then
exec "$0"
elif [[ "$?" == "1" ]]; then
exit
fi