Minor update, some new scripts, some updated
sss: save some space, picture compressor pdfdiff : perform a visual diff on simila pdfs to highlight
This commit is contained in:
parent
d32fbc1205
commit
938bd641a2
38
pdfdiff
Normal file
38
pdfdiff
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
# pdfdiff : perform a graphical diff on two similar pdf files, and highlight the differences
|
||||||
|
# Usage : pdfdiff SOURCE1 SOURCE2 [OUTPUT]
|
||||||
|
#
|
||||||
|
# Dependencies: mutool (https://mupdf.com) ; ImageMagikc (imagemagick.org)
|
||||||
|
|
||||||
|
tmpdir=$(mktemp -d)
|
||||||
|
|
||||||
|
cp "${1}" "${tmpdir}/a.pdf"
|
||||||
|
cp "${2}" "${tmpdir}/b.pdf"
|
||||||
|
|
||||||
|
cd "${tmpdir}"
|
||||||
|
|
||||||
|
n=$(mutool info a.pdf | grep -im1 "Pages: " | cut -d " " -f 2)
|
||||||
|
m=$(mutool info b.pdf | grep -im1 "Pages: " | cut -d " " -f 2)
|
||||||
|
|
||||||
|
if test "${n}" != "${m}" ; then
|
||||||
|
read -p "Warning: Source PDFs do not have the same number of pages. Continue ? [Y/n]"
|
||||||
|
test "${REPLY}" = "n" || test "${REPLY}" = "N" && exit 0
|
||||||
|
test "${n}" -gt "${m}" && n="${m}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mutool draw -F png -A 0 -N -o a-%d.png a.pdf
|
||||||
|
mutool draw -F png -A 0 -N -o b-%d.png b.pdf
|
||||||
|
|
||||||
|
for i in $(seq 1 "${n}") ; do
|
||||||
|
compare "a-${i}.png" "b-${i}.png" -compose src "diff-${i}.png"
|
||||||
|
montage "a-${i}.png" "diff-${i}.png" "b-${i}.png" -tile 3x1 -geometry +0+0 "out-${i}.png"
|
||||||
|
done
|
||||||
|
|
||||||
|
convert $(ls -v out*.png) out.pdf
|
||||||
|
|
||||||
|
cd -
|
||||||
|
mv "${tmpdir}/out.pdf" "${3:-./diff.pdf}"
|
||||||
|
|
||||||
|
rm -rf "${tmpdir}"
|
54
sss
54
sss
@ -1,7 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# TODO: Read the doc about optipng for further compression ?
|
||||||
|
|
||||||
usage="\
|
usage="\
|
||||||
Usage: $0 [-p PREFIX] [-s SUFFIX] [-e EXTENSION] [-g \"GEOMETRY\"] [-q QUALITY] [-v] image1 image2 image3 ...\n
|
Usage: $0 [-p PREFIX] [-s SUFFIX] [-e EXTENSION] [-g \"GEOMETRY\"] [-q QUALITY] [-vntP] image1 image2 image3 ...\n
|
||||||
Use ImageMagick's convert tool to reduce the size of a selection of image files.\n
|
Use ImageMagick's convert tool to reduce the size of a selection of image files.\n
|
||||||
\n
|
\n
|
||||||
Options:\n
|
Options:\n
|
||||||
@ -30,6 +32,7 @@ Use ImageMagick's convert tool to reduce the size of a selection of image files.
|
|||||||
\t\tBest compression, most loss of quality. Default off\n
|
\t\tBest compression, most loss of quality. Default off\n
|
||||||
-v\t\tMake verbose\n
|
-v\t\tMake verbose\n
|
||||||
-P\t\tPrint progress (for use with zenity --progress)\n
|
-P\t\tPrint progress (for use with zenity --progress)\n
|
||||||
|
-n\t\tNo changes. Simulate only, print the command lines but do not run them.
|
||||||
-h\t\tPrint this help and exit.\n"
|
-h\t\tPrint this help and exit.\n"
|
||||||
|
|
||||||
if [[ $# == 0 ]] ; then echo -e $usage ; exit 0 ; fi
|
if [[ $# == 0 ]] ; then echo -e $usage ; exit 0 ; fi
|
||||||
@ -40,10 +43,11 @@ geom="1920x1080>"
|
|||||||
qual="85"
|
qual="85"
|
||||||
ext="jpg"
|
ext="jpg"
|
||||||
verbose=false
|
verbose=false
|
||||||
|
nochange=""
|
||||||
sampling="-sampling-factor 4:2:0"
|
sampling="-sampling-factor 4:2:0"
|
||||||
median="2x2-1-1"
|
median="2x2-1-1"
|
||||||
|
|
||||||
while getopts p:s:g:q:M:e:xGmhSvPt option ; do
|
while getopts p:s:g:q:M:e:xGmhSvPnt option ; do
|
||||||
case "${option}"
|
case "${option}"
|
||||||
in
|
in
|
||||||
p) ((nopt+=2)) ;
|
p) ((nopt+=2)) ;
|
||||||
@ -79,6 +83,9 @@ while getopts p:s:g:q:M:e:xGmhSvPt option ; do
|
|||||||
G) ((nopt+=1)) ;
|
G) ((nopt+=1)) ;
|
||||||
gaussian=true;
|
gaussian=true;
|
||||||
;;
|
;;
|
||||||
|
n) ((nopt+=1)) ;
|
||||||
|
nochange=true;
|
||||||
|
;;
|
||||||
m) ((nopt+=1)) ;
|
m) ((nopt+=1)) ;
|
||||||
unset median
|
unset median
|
||||||
;;
|
;;
|
||||||
@ -106,38 +113,37 @@ test $verbose == true && echo -e "Old file \t Old size \t Old res \t New res \t
|
|||||||
|
|
||||||
for f in "${@:$nopt}" ; do
|
for f in "${@:$nopt}" ; do
|
||||||
|
|
||||||
test "$verbose" == true && status="$f \t $(ls -lh $f | cut -d " " -f 5) \t $(identify $f | rev | cut -d " " -f 7 | rev) \t " ; size=$(ls -l "$f" | cut -d " " -f 5)
|
test "$verbose" == true && status="$f \t $(ls -lh $f | cut -d " " -f 5) \t $(identify "${f}" | rev | cut -d " " -f 7 | rev) \t " ; size=$(ls -l "${f}" | cut -d " " -f 5)
|
||||||
|
|
||||||
name="$(echo $f | rev | cut -d '.' -f 2- | rev)"
|
name="$(echo $f | rev | cut -d '.' -f 2- | rev)"
|
||||||
ext="${EXT:-$(echo $f | rev | cut -d '.' -f 1 | rev)}"
|
ext="${EXT:-$(echo $f | rev | cut -d '.' -f 1 | rev)}"
|
||||||
|
|
||||||
test "$time" && exif -m -t "DateTime" "$f" > /dev/null && name="$(exif -m -t "DateTime" $f | tr ": " ".-")" || echo "$f : no DateTime found in exif data. Using filename instead."
|
if test "$time" ; then
|
||||||
|
tmp="$(exif -m -t "DateTime" "${f}")" && name="$(echo ${tmp} | tr ": " "-_" | head -n 1)" || echo "$f : no DateTime found in exif data. Using filename instead."
|
||||||
|
tmp="$(echo "${f}" | grep -E "([[:digit:]]{4}).?([[:digit:]]{2}).?([[:digit:]]{2}).?([[:digit:]]{2}).?([[:digit:]]{2}).?([[:digit:]]{2})" | sed -e "s/[^0-9]//g" | sed -E "s/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/\1-\2-\3_\4-\5-\6/")"
|
||||||
|
test "${tmp}" && name="${tmp}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
nf="${prefix}${name}${suffix}.${ext}"
|
||||||
|
|
||||||
nf="$prefix""$name""$suffix"."$ext"
|
while test -e $nf ; do nf="${prefix}${name}${suffix}"_$(((++i)))."${ext}" ; done
|
||||||
|
|
||||||
while test -e $nf ; do nf="$prefix""$name""$suffix"_$(((++i)))."$ext" ; done
|
|
||||||
unset i
|
unset i
|
||||||
|
|
||||||
((insize+=$(ls -l "$f" | cut -d " " -f 5)))
|
((insize+=$(ls -l "${f}" | cut -d " " -f 5)))
|
||||||
|
|
||||||
convert \
|
cmd="convert -auto-orient -define jpeg:dct-method=float $sampling ${median:+-median $median} -interlace Plane ${gaussian:+-gaussian-blur 0.1} -colorspace RGB -resize ${geom} -quality ${qual} ${f} ${nf}"
|
||||||
-auto-orient \
|
test "$exif" = true && cmd="$cmd ; exif --remove --no-fixup -o ${nf} ${nf} > /dev/null"
|
||||||
-define jpeg:dct-method=float \
|
|
||||||
$sampling \
|
if test "${nochange}" ; then
|
||||||
${median:+\-median $median} \
|
echo "${cmd}"
|
||||||
-interlace Plane \
|
else
|
||||||
${gaussian:+-gaussian-blur 0.1} \
|
$cmd
|
||||||
-colorspace RGB \
|
|
||||||
-resize "$geom" \
|
|
||||||
-quality "$qual" "$f" "$nf";
|
|
||||||
|
|
||||||
test "$exif" = true && exif --remove --no-fixup -o $nf $nf > /dev/null
|
((outsize+=$(ls -l "${nf}" | cut -d " " -f 5)))
|
||||||
|
test "$verbose" == true && echo -e $status"$(identify "$nf" | rev | cut -d " " -f 7 | rev) \t $(ls -lh "$nf" | cut -d " " -f 5) \t "$nf" \t $((100*$(ls -l "$nf" | cut -d " " -f 5)/$size))% "
|
||||||
((outsize+=$(ls -l "$nf" | cut -d " " -f 5)))
|
fi
|
||||||
|
|
||||||
test $verbose == true && echo -e $status"$(identify "$nf" | rev | cut -d " " -f 7 | rev) \t $(ls -lh "$nf" | cut -d " " -f 5) \t "$nf" \t $((100*$(ls -l "$nf" | cut -d " " -f 5)/$size))% "
|
test "$progress" && echo "$(((++progress * 100 / $#)))"
|
||||||
|
|
||||||
test $progress && echo $(((++progress * 100 / $#)))
|
|
||||||
done
|
done
|
||||||
|
|
||||||
test $verbose == true && echo -e "Average compression : $((100*outsize/insize))%"
|
test $verbose == true && echo -e "Average compression : $((100*outsize/insize))%"
|
||||||
|
4
xmute
Normal file
4
xmute
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
pid=$(xprop | grep -i pid | cut -d "=" -f 2 | tr -dc "0-9")
|
||||||
|
index=$(pacmd list-sink-inputs | grep -B30 "application.process.id = \"$pid\"" | grep -m1 "index:" | cut -d ":" -f 2 | tr -dc "0-9")
|
||||||
|
pacmd list-sink-inputs | grep -A30 "index: $index" | grep -q "muted: no" && pacmd set-sink-input-mute $index true || pacmd set-sink-input-mute $index false
|
4
xpause
4
xpause
@ -30,13 +30,13 @@ if test -s /tmp/xpause ; then
|
|||||||
echo "unpaused $pid"
|
echo "unpaused $pid"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
echo "xpause FAILED (kill)"
|
echo "xunpause FAILED (kill -SIGCONT \"$pid\")"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo $pid >> /tmp/xpause
|
echo $pid >> /tmp/xpause
|
||||||
kill -s "SIGSTOP" $pid || ( echo "xpause FAILED (kill)" ; exit 1 )
|
kill -s "SIGSTOP" $pid || ( echo "xpause FAILED (kill - SIGSTOP $pid)" ; exit 1 )
|
||||||
echo "xpaused $pid"
|
echo "xpaused $pid"
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user