-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwallutils.sh
executable file
·219 lines (185 loc) · 6.33 KB
/
wallutils.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
#!/bin/bash
#####################################################
## utilities for wallpaper generation on instantOS ##
#####################################################
RAW="https://raw.githubusercontent.com/instantOS/instantLOGO/main"
setupres() {
export RESOLUTION=$(iconf max:1920x1080)
}
setupres
# resize an image using imagemagick
imgresize() {
if file "$1" | grep -q "image data"; then
echo "image found"
else
echo "$1 is not an image"
curl -s google.com || exit 1
instantwallpaper w
exit
fi
IMGRES=$(identify "$1" | grep -o '[0-9][0-9]*x[0-9][0-9]*' | sort -u | head -1)
if [ "$IMGRES" = "$2" ]; then
echo "image already resized"
if [ -n "$3" ]; then
if ! [ -e "$3" ]; then
cp "$1" "$3"
fi
fi
return 0
fi
mv "$1" "${1%.*}.1.png"
convert "${1%.*}.1.png" -alpha on -background none \
-gravity center -resize "$2^" -gravity center -extent "$2" "${3:-$1}"
rm "${1%.*}.1.png"
}
instantoverlay() {
if [ -e ~/instantos/wallpapers/customlogo.png ]; then
rsync -aP ~/instantos/wallpapers/customlogo.png ./overlay.png
else
if [ -e overlay.png ] && file overlay.png | grep -iq 'image data'; then
return
else
[ -e overlay.png ] && rm overlay.png
wget -q "https://raw.githubusercontent.com/instantOS/instantLOGO/main/wallpaper/overlay.png"
fi
fi
}
# bing daily photo
bingwallpaper() {
echo "downloading bing wallpaper"
wget -qO photo.jpg "$(curl -s https://bing.biturl.top/ | grep -Eo 'www.bing.com/[^"]*(jpg|png)')"
}
googlewallpaper() {
echo "downloading wallpaper from google"
LINK="$(curl -s https://raw.githubusercontent.com/dconnolly/chromecast-backgrounds/master/README.md |
shuf | head -1 | grep -o 'http[^ )]*')"
wget -qO photo.jpg "$LINK"
}
wallhaven() {
echo "downloading wallpaper from wallhaven"
WALLURL=$(curl -Ls 'https://wallhaven.cc/search?q=id%3A711&categories=111&purity=100&sorting=random&order=desc' |
grep -o 'https://wallhaven.cc/w/[^"]*' | shuf | head -1)
wget -qO photo.jpg "$(curl -s "$WALLURL" | grep -o 'https://w.wallhaven.cc/full/.*/.*.jpg' | head -1)"
}
wallist() {
echo "downloading wallpaper from list"
wget -qO photo.jpg "$(curl -s 'https://raw.githubusercontent.com/instantOS/instantWALLPAPER/main/list.txt' | shuf | head -1)"
}
viviwall() {
echo "vk pictures wallpaper"
LINK="$(curl -s https://github.com/instantOS/wallpapers/tree/main/wallpapers | grep -o 'wall[0-9]*\.jpg' | sort -u | shuf | head -1)"
wget -qO photo.jpg "https://raw.githubusercontent.com/instantOS/wallpapers/main/wallpapers/$LINK"
}
# generate default mono colored logo wallpaper
defaultwall() {
instantoverlay
imgresize overlay.png "$RESOLUTION"
if [ -n "$3" ]
then
OUTNAME="$3"
else
OUTNAME="$(iconf theme:arc)"
fi
if [ -n "$1" ] && [ -n "$2" ]; then
echo "generating custom image"
convert overlay.png -fill "$1" -colorize 100 color.png
convert color.png -background "$2" -alpha remove -alpha off "$OUTNAME".png
else
echo "defaulting to theme colors"
convert overlay.png -fill "$(instantthemes query colors.accent "#88B2F6")" -colorize 100 color.png
convert color.png -background "$(instantthemes query colors.background "#121212")" -alpha remove -alpha off "$OUTNAME".png
fi
rm color.png
}
# checks if file is a valid image
checkwall() {
if [ -e "$1" ] && file "$1" | grep -q 'image data'; then
echo "image found"
return 0
else
echo "not an image"
return 1
fi
}
# choose a wallpaper in a gui
guiwall() {
WALLPATH="$(zenity --file-selection --file-filter='Image files (png, jpg) | *.png *.jpg')"
if [ -z "$WALLPATH" ]; then
echo "no wallpaper chosen"
exit
fi
checkwall "$WALLPATH" || exit 1
}
# put the logo onto a wallpaper
compwallpaper() {
echo "RESOLUTION $RESOLUTION"
imgresize "${1:-photo.jpg}" "$RESOLUTION" wall.png || return 1
# the logo is optional
if ! iconf -i nologo; then
instantoverlay
imgresize overlay.png "$RESOLUTION"
# create mask from overlay
convert overlay.png -alpha extract mask.png
# cut the image with the mask
composite -compose CopyOpacity mask.png wall.png cut.png
# Convert to black and white the cut
# convert cut.png -colorspace Gray blackandwhite.png
# Negate the black and white cut
convert cut.png -channel RGB -negate invert.png
# draw the computed overlay on top of the background
convert wall.png invert.png -gravity center -composite instantwallpaper.png
rm wall.png
rm mask.png
rm cut.png
rm blackandwhite.png
rm invert.png
else
echo "logo disabled"
mv wall.png instantwallpaper.png
fi
}
# work through a list of fallback wallpapers
# exit if one of them is found
fallbackwallpaper() {
echo "offlinewall"
if ! [ -e ~/instantos/wallpapers/ ]; then
exit
fi
cd ~/instantos/wallpapers/
setwallpaper() {
if [ -e "$1" ]; then
ifeh "$1"
exit
fi
}
setwallpaper custom.png
setwallpaper instantwallpaper.png
setwallpaper default/"$(cat ../themes/config)".png
setwallpaper /opt/instantos/wallpapers/default.png
exit
}
# predownload all list wallpapers
fetchwallpapers() {
if ! [ -e "$(xdg-user-dir PICTURES)/wallpapers" ]; then
mkdir -p "$(xdg-user-dir PICTURES)/wallpapers"
fi
cd "$(xdg-user-dir PICTURES)/wallpapers" || return 1
rm readme.jpg
if [ "$(ls | wc -l)" -gt 6 ]; then
echo "wallpapers already downloaded"
echo "remove $(xdg-user-dir PICTURES)/wallpapers to redownload them"
exit
fi
if ! checkinternet; then
echo "internet it required"
notify-send "internet it required to fetch wallpapers"
exit
fi
curl -s https://raw.githubusercontent.com/instantOS/instantWALLPAPER/main/list.txt | grep -v '512pixels.net' >/tmp/instantwallpaperlist
WALLCOUNTER=1
while read p; do
echo "Downloading wallpaper $WALLCOUNTER"
wget -qO "$WALLCOUNTER.jpg" "$p"
WALLCOUNTER="$((WALLCOUNTER + 1))"
done </tmp/instantwallpaperlist
}