2022-02-10 20:11:56 +01:00
|
|
|
#--------------------------------
|
|
|
|
# filename: /zsh/scripts
|
|
|
|
#--------------------------------
|
|
|
|
|
|
|
|
# Search for string in all files in pwd
|
|
|
|
function f() {
|
|
|
|
grep -rnw ./ -e "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# mkdir and cd
|
|
|
|
function mkcd() {
|
|
|
|
mkdir -p "$@" && cd "$_";
|
|
|
|
}
|
|
|
|
|
|
|
|
# pushover notification
|
|
|
|
function pushover() {
|
|
|
|
curl -s \
|
|
|
|
--form-string "token=$pushover_token" \
|
|
|
|
--form-string "user=$pushover_user" \
|
|
|
|
--form-string "title=$HOST" \
|
|
|
|
--form-string "message=$1" \
|
|
|
|
https://api.pushover.net/1/messages.json
|
|
|
|
}
|
|
|
|
|
|
|
|
# png to jpg 85
|
|
|
|
function png2web() {
|
|
|
|
findpath=$1
|
|
|
|
: ${findpath:="."}
|
|
|
|
find "$findpath" -name '*.png' | while read f ; do
|
|
|
|
dir=$(dirname "$f");
|
|
|
|
file=$(basename "$f");
|
|
|
|
name="${file%.*}";
|
|
|
|
magick convert "$f" pnm:- | cjpeg -progressive -quality 85 > "$dir/$name.jpg" </dev/null
|
|
|
|
rm -f "$f";
|
|
|
|
done
|
|
|
|
}
|
2022-02-10 21:29:04 +01:00
|
|
|
|
|
|
|
function jpeg1024() {
|
2022-02-14 00:00:11 +01:00
|
|
|
magick "$1" -resize '1024x1024\>' -background black -flatten TGA:- | cjpeg -targo -quality 75 -optimize -progressive -outfile $1.jpg
|
|
|
|
}
|
2022-04-19 17:48:35 +02:00
|
|
|
|
|
|
|
# Make PDFs look like scanned
|
|
|
|
# src: https://gist.github.com/andyrbell/25c8632e15d17c83a54602f6acde2724?permalink_comment_id=3295405#gistcomment-3295405
|
|
|
|
function pdf-like-scanned () {
|
|
|
|
OUT=$(basename "$1" .pdf)
|
|
|
|
convert -density 150 "$1" -rotate "$([ $((RANDOM % 2)) -eq 1 ] && echo -)0.$(($RANDOM % 4 + 5))" \
|
|
|
|
-attenuate 0.4 +noise Multiplicative -attenuate 0.03 +noise Multiplicative -sharpen 0x1.0 \
|
|
|
|
-colorspace Gray "$OUT"_scanned.pdf
|
|
|
|
}
|