-
Notifications
You must be signed in to change notification settings - Fork 1
/
alpha_restore.sh
executable file
·44 lines (37 loc) · 1.24 KB
/
alpha_restore.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
#!/bin/sh
# path: /home/klassiker/.local/share/repos/shell/alpha_restore.sh
# author: klassiker [mrdotx]
# github: https://github.com/mrdotx/shell
# date: 2023-08-02T19:25:13+0200
# help
script=$(basename "$0")
help="$script [-h/--help] -- script to find png files with suspicious data
in alpha channel
Usage:
$script [png files]
Examples:
$script test.png
$script test1.png test2.png test3.png"
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ $# -eq 0 ]; then
printf "%s\n" "$help"
exit 1
else
tmp_directory=$(mktemp -t -d alpha_restore.XXXXXX)
suspicious=0
printf ":: suspicious files\n"
for f in "$@"; do
convert "$f" -strip -alpha extract "$tmp_directory/alpha_extract.rgb"
if ! (hexdump -ve '"%.2x"' "$tmp_directory/alpha_extract.rgb" \
| grep -q '^f*$' \
); then
printf " %s\n" "$f"
cp "$f" "$tmp_directory"
convert -strip -alpha off "$f" \
"$tmp_directory/$(basename "$f").noalpha.png"
suspicious=1
fi
done
[ $suspicious -eq 1 ] \
&& printf "\n:: please inspect files in %s\n" "$tmp_directory" \
|| printf "\n:: no suspicious files\n"
fi