Skip to content

Commit 43e4c10

Browse files
committed
Adding shot-magick
1 parent 1628bf1 commit 43e4c10

File tree

5 files changed

+472
-19
lines changed

5 files changed

+472
-19
lines changed

.local/bin/shot

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/data/data/com.termux/files/usr/bin/env bash
2+
SAVE_DIR=/sdcard/Pictures/Screenshots
3+
ORI_DIR=ORI
4+
5+
mkdir -p $SAVE_DIR/$ORI_DIR
6+
7+
[ $1 ] && sec=$1 || sec=5
8+
9+
{
10+
clear
11+
echo -e "\e[94m[!] screenshot will be taken in ${1}s ..."
12+
echo -e "\e[0m"
13+
14+
{
15+
sleep $sec &&
16+
SAVE_NAME=$(echo -e "Screenshot-$(date +'%d-%m-%Y_%r').png"|sed 's/://g;s/ //g') &&
17+
sudo screencap -p $SAVE_DIR/$SAVE_NAME
18+
{
19+
A=$(termux-dialog confirm -i \
20+
"Screenshot has successfully taken.
21+
22+
Now prettifying using imagemagick.
23+
24+
Please wait a moment ..." | jq '.text')
25+
26+
[[ $A == '"no"' ]] && B=$(termux-dialog \
27+
confirm \
28+
-i "Cancel Conversion now?" | jq '.text')
29+
30+
[[ $B == '"yes"' ]] && termux-dialog confirm \
31+
-i "Conversion Aborted." && pkill bash &&
32+
pkill convert
33+
} &
34+
35+
sleep 0.1
36+
37+
bash \
38+
$HOME/.scripts/shot-magick \
39+
$SAVE_DIR/$SAVE_NAME \
40+
-r -c
41+
42+
mv $SAVE_DIR/$SAVE_NAME $SAVE_DIR/$ORI_DIR
43+
44+
} >/dev/null
45+
46+
SAVE_NAME="$(echo $SAVE_NAME|sed 's/.png$//')_ShotMg.png"
47+
48+
A=$(termux-dialog confirm \
49+
-t "Screenshot saved!" \
50+
-i "Your screenshot has been saved in:
51+
52+
$SAVE_DIR/${SAVE_NAME}
53+
54+
Open it now?" |
55+
jq '.text')
56+
57+
[[ $A == '"yes"' ]] && xdg-open "$SAVE_DIR/$SAVE_NAME"
58+
} &
59+

.scripts/shot-magick

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
#!/usr/bin/env bash
2+
# Github : https://github.com/annzc
3+
# telegram: @bluetterphiley
4+
# MIT LICENSE <3
5+
6+
#R="\e[91m"
7+
#G="\e[92m"
8+
#B="\e[94m"
9+
#Y="\e[93m"
10+
#C="\e[96m"
11+
#O="\e[0m"
12+
13+
_VERSION="0.2-beta"
14+
_PROG="shot-magick"
15+
_GITHUB="https://github.com/annzc/shot-magick"
16+
17+
_OPTIONS=( \
18+
'-h' '--help' \
19+
'-v' '--version' \
20+
'-r' '--rounded' \
21+
'-d' '--dark' \
22+
'-t' '--usertag' \
23+
'-c' '--notag' \
24+
'-f' '--file' \
25+
'-o' '--output' \
26+
)
27+
_OPSI_USER=( "$2" "$3" "$4" "$5" )
28+
29+
_FILE="$1"
30+
_NEME=$(echo $1|awk -F '/' '{print $NF}')
31+
_FUCC=$(echo $_NEME | sed 's/[ ]*/WTF/g')
32+
_FILE_EXT=$(echo "$1" | awk -F "." '{print $NF}')
33+
_FILE_NAME=$(echo "$1" | sed "s/.$_FILE_EXT$//")
34+
_FILE_ANU="ShotMg"
35+
_FILE_RES="${_FILE_NAME}_${_FILE_ANU}.$_FILE_EXT"
36+
_PNG=".buff.png"
37+
38+
_MODE="light" # default
39+
40+
# Tag setup
41+
_TAG_FG="#0e1419"
42+
_TAG_BG="none"
43+
_TAG_SIZE=13
44+
_TAG_GRAVITY="Northwest"
45+
_TAG_ANNOTATE="+40+2"
46+
_TAG_DEFAULT="Ann @ Redmi6A $(date +'%d-%m-%Y %r')"
47+
_TAG_FONT="Iosevka-Mayukai-Medium-Nerd-Font-Complete"
48+
# to display list font, run:
49+
# convert -list font | grep -iE 'font:.*'
50+
51+
# Shadow setup
52+
_SHADOW_SIZE="50x10+0+10"
53+
_SHADOW_COLOR="#000000"
54+
55+
# Border setup
56+
_BORDER_COLOR="#abb2bf"
57+
58+
# user options
59+
#[[ ${_OPSI_USER[*]} =~ "-f" ]] ||
60+
# [[ ${_OPSI_USER[*]} =~ "--file" ]] &&
61+
# for v in ${_OPSI_USER[@]}
62+
63+
[[ ${_OPSI_USER[*]} =~ "--notag" ]] ||
64+
[[ ${_OPSI_USER[*]} =~ "-c" ]] &&
65+
_IS_TAG=false || _IS_TAG=true
66+
67+
if [[ ${_OPSI_USER[*]} =~ "--usertag" ]] ||
68+
[[ ${_OPSI_USER[*]} =~ "-t" ]]; then
69+
if [ -f .usertag ]; then
70+
_TAG_FROM=.usertag
71+
_USER_TAG="$(cat .usertag)"
72+
else
73+
echo -ne "input user tag:\n> "
74+
read -e _usertag
75+
_TAG_FROM="user input"
76+
_USER_TAG="$(echo $_usertag)"
77+
fi
78+
else
79+
_TAG_FROM="default tag"
80+
_USER_TAG="$_TAG_DEFAULT"
81+
fi
82+
83+
[[ ${_OPSI_USER[*]} =~ "--rounded" ]] ||
84+
[[ ${_OPSI_USER[*]} =~ "-r" ]] &&
85+
_IS_ROUNDED=true || _IS_ROUNDED=false
86+
87+
[[ ${_OPSI_USER[*]} =~ "--dark" ]] ||
88+
[[ ${_OPSI_USER[*]} =~ "-d" ]] &&
89+
_MODE="dark" _TAG_FG="#61afef"
90+
91+
[[ $_MODE == "dark" ]] &&
92+
_BORDER_COLOR="#0e1419" _SHADOW_COLOR="#61afef"
93+
94+
_apani="
95+
$_PROG v$_VERSION
96+
Program sederhana untuk mempercantik(?) hasil screenshot.
97+
"
98+
99+
_apani_cara_pakai="
100+
USAGE
101+
./shot-magick [-h|--help|-v|--version]
102+
./shot-magick [img.ext] [OPSI]
103+
"
104+
105+
_apani_contoh="
106+
EXAMPLE
107+
./shot-magick img.jpg --dark
108+
./shot-magick img.png --rounded --dark
109+
./shot-magick img.jpg --dark --usertag
110+
"
111+
112+
_apani_opsi="
113+
OPTIONS
114+
-r [--rounded] - menumpulkan bagian sudut gambar
115+
-d [--dark] - border mode gelap
116+
-t [--usertag] - menyesuaikan bagian isi tag
117+
-c [--notag] - tidak ada tag
118+
"
119+
120+
_setup_() {
121+
echo
122+
}
123+
124+
_help_() {
125+
echo -e " \
126+
$_apani \
127+
$_apani_cara_pakai \
128+
$_apani_opsi \
129+
$_apani_contoh"
130+
}
131+
132+
_version_() {
133+
echo -e "
134+
$_PROG v$_VERSION\n${O}Github: $_GITHUB
135+
"
136+
}
137+
138+
_unknown_() {
139+
[[ ${_OPTIONS[*]} =~ "$_FILE" ]] &&
140+
case "$_FILE" in
141+
-|--)
142+
echo -e "tidak ditemukan argumen '$_FILE'. lihat --help"
143+
;;
144+
-*)
145+
echo -e "penggunaan salah! coba dengan --help"
146+
;;
147+
esac ||
148+
echo -e "tidak ditemukan argumen '$_FILE'. lihat '--help'"
149+
}
150+
151+
_nofile_() {
152+
echo -e "file '$_FILE' tidak dapat ditemukan"
153+
}
154+
155+
_result_() {
156+
echo -e "
157+
Details~~~
158+
159+
{
160+
\t'file' : '$_FILE'
161+
\t'rounded' : '$_IS_ROUNDED'
162+
\t'mode' : '$_MODE'
163+
\t'tag' : '$($_IS_TAG && echo $_USER_TAG || echo notag)'
164+
\t'result' : '$_FILE_RES'
165+
}
166+
" | sed 's/^[ ]*//g'
167+
}
168+
169+
_convert_() {
170+
{
171+
cp "$_FILE" $_FUCC 2>&1
172+
echo
173+
echo converting...
174+
convert "$_FUCC" $_PNG
175+
sleep 0.1
176+
177+
echo -n "rounded corner... "
178+
$_IS_ROUNDED &&
179+
echo yes &&
180+
_rounded_corner_ ||
181+
echo no
182+
183+
[[ $_MODE == "light" ]] && #_inborder_
184+
$_IS_ROUNDED && _rounded_corner_
185+
186+
_shadow_
187+
_border_
188+
189+
echo -n "adding tag... "
190+
$_IS_TAG &&
191+
echo "yes ($_TAG_FROM)" &&
192+
_tag_ ||
193+
echo no
194+
195+
echo final convert...
196+
convert $_PNG "$_FILE_RES"
197+
198+
rm $_PNG $_FUCC
199+
}
200+
}
201+
202+
_usrarg_() {
203+
case "$1" in
204+
-h|--help ) _help_ ;;
205+
-v|--version ) _version_ ;;
206+
-* ) _unknown_ ;;
207+
esac
208+
}
209+
210+
#######################################
211+
################ MAIN #################
212+
main() {
213+
[ ! $1 ] &&
214+
_help_ &&
215+
exit 1
216+
217+
[ -f "$_FILE" ] &&
218+
{
219+
_convert_ &&
220+
_result_ ||
221+
echo -e "Convert failed" &&
222+
exit 1
223+
}
224+
225+
[[ "$1" =~ -* ]] &&
226+
_usrarg_ $1 &&
227+
exit 0
228+
229+
_nofile_ &&
230+
exit 1
231+
}
232+
################ MAIN #################
233+
#######################################
234+
235+
_rounded_corner_() {
236+
convert $_PNG \
237+
\( \
238+
+clone \
239+
-alpha extract -draw \
240+
'fill black polygon 0,0 0,30 30,0 fill white circle 30,30 30,0'\
241+
\( +clone -flip \) \
242+
-compose Multiply -composite \
243+
\( +clone -flop \) \
244+
-compose Multiply -composite \
245+
\) \
246+
-alpha off \
247+
-compose CopyOpacity -composite $_PNG
248+
}
249+
250+
_shadow_() {
251+
convert $_PNG \
252+
\( +clone \
253+
-background "$_SHADOW_COLOR" \
254+
-shadow $_SHADOW_SIZE \) \
255+
+swap \
256+
-background none \
257+
-layers merge \
258+
+repage $_PNG
259+
}
260+
261+
_border_() {
262+
convert $_PNG \
263+
-bordercolor "$_BORDER_COLOR" \
264+
-border 70 $_PNG
265+
}
266+
267+
_tag_() {
268+
echo -en " $_USER_TAG " |
269+
convert $_PNG \
270+
-gravity $_TAG_GRAVITY \
271+
-pointsize $_TAG_SIZE \
272+
-fill $_TAG_FG \
273+
-undercolor $_TAG_BG \
274+
-font $_TAG_FONT \
275+
-annotate $_TAG_ANNOTATE \
276+
@- $_PNG
277+
}
278+
279+
#_inborder_() {
280+
# convert $_PNG -border 3 $_PNG
281+
#}
282+
283+
__end() { # for debugging
284+
_result_
285+
exit 1
286+
}
287+
288+
#__end
289+
main $1 $2 $3 $4

.termux/colors.properties

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
foreground=#c8ccd4
2-
background=#1e222a
3-
cursor=#abb2bf
4-
color0=#1e222a
5-
color1=#e06c75
6-
color2=#98c379
7-
color3=#e5c07b
8-
color4=#61afef
9-
color5=#c678dd
10-
color6=#56b6c2
11-
color7=#abb2bf
12-
color8=#545862
13-
color9=#e06c75
14-
color10=#98c379
15-
color11=#e5c07b
16-
color12=#61afef
17-
color13=#c678dd
18-
color14=#56b6c2
19-
color15=#c8ccd4
1+
color0=#2f343f
2+
color1=#fd6b85
3+
color2=#63e0be
4+
color3=#fed270
5+
color4=#67d4f2
6+
color5=#ff8167
7+
color6=#63e0be
8+
color7=#eeeeee
9+
color8=#4f4f5b
10+
color9=#fd6b85
11+
color10=#63e0be
12+
color11=#fed270
13+
color12=#67d4f2
14+
color13=#ff8167
15+
color14=#63e0be
16+
color15=#eeeeee
17+
background=#2a2c3a
18+
foreground=#eeeeee
19+
cursor=#fd6b85

.termux/font.ttf

301 KB
Binary file not shown.

0 commit comments

Comments
 (0)