+ imgResize.sh & rotate.sh

This commit is contained in:
committer@tuxwarrior
2026-03-04 11:43:52 -05:00
parent c4bd8a9c94
commit 21c1b3c1a7
4 changed files with 95 additions and 13 deletions

View File

@@ -203,22 +203,10 @@ nas() {
# multimedia
# ---
# downstream() {
# output="output.mp4"
# # https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
# if [[ -n $2 ]]; then
# output=$2
# fi
# ffmpeg -i "$1" -c copy -bsf:a aac_adtstoasc "/home/poq/syncDir/0_downloads/${output}"
# }
#alias videoCompressor="/home/poq/syncDir/gitRepos/gi.op.fo/miniProjects/2104_videoCompressor/src/vc_v2.sh"
#alias videoWatermark="/home/poq/syncDir/gitRepos/gi.op.fo/miniProjects/2104_videoCompressor/src/vcwm_v1.sh"
#alias toJpg='/home/poq/syncDir/gitRepos/gi.op.fo/miniProjects/2306_toJpg/toJpg.sh'
#imgResize() {
# /home/poq/syncDir/gitRepos/gi.op.fo/miniProjects/2305_imgResizer/resize.sh 1200 "$1" jpg
#}
# https://itsfoss.com/compress-pdf-linux/
pdfCompress() {
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/ebook \

View File

@@ -360,3 +360,14 @@
---
#alias keymap="setxkbmap -model pc105 -layout us,no -option grp:caps_toggle,grp_led:scroll"
---
# downstream() {
# output="output.mp4"
# # https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
# if [[ -n $2 ]]; then
# output=$2
# fi
# ffmpeg -i "$1" -c copy -bsf:a aac_adtstoasc "/home/poq/syncDir/0_downloads/${output}"
# }

39
dots/bin/imgResize.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# 26.03.04 :: klevstul
resize() {
test_integer() {
if ! [[ $1 =~ ^[1-9][0-9]*$ ]]; then
echo "error: variable (image width) must be an integer"
exit 1
fi
}
filename=$1 # ~/syncDir/0_downloads/frodeKlevstul.jpg
extension="${filename##*.}" # jpg
basename_without_ext="${filename%.*}" # ~/syncDir/0_downloads/frodeKlevstul
basename_only="${basename_without_ext##*/}" # frodeKlevstul
width=$2
width=${width:=1000} # default: 1000
test_integer ${width} # make sure the input (if given from the user) is valid
# scale=1000:-1: resizes the image to a width of 1000 pixels, automatically calculating the height to preserve the original aspect ratio.
# -q:v 90: sets the jpeg quality to 90 (lower values mean higher quality; 90 is a high quality setting for jpeg).
ffmpeg -i ${filename} -vf "scale=${width}:-1" -q:v 90 ${basename_without_ext}_rzd.jpg
}
this_file_name=`basename "$0"`
if [ $# -lt 1 ]; then
echo "error: path to file is missing."
echo "usage: '$this_file_name [path_to_file] ([width (1000)])'"
exit 1
fi
resize $1 $2

44
dots/bin/rotate.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# 26.03.04 :: klevstul
rotate() {
test_integer() {
if ! [[ $1 =~ ^[123]$ ]]; then
echo "error: variable (times to rotate) must be 1, 2, or 3"
exit 1
fi
}
filename=$1 # ~/syncDir/0_downloads/frodeKlevstul.jpg
extension="${filename##*.}" # jpg
basename_without_ext="${filename%.*}" # ~/syncDir/0_downloads/frodeKlevstul
basename_only="${basename_without_ext##*/}" # frodeKlevstul
times_to_rotate=$2 # how many times to rotate 90 degrees
times_to_rotate=${times_to_rotate:=1} # set to 1 if no value is given
test_integer ${times_to_rotate} # make sure the input (if given from the user) is valid
transpose="transpose=1" # add a transpose for each time to rotate
for ((i = 2; i <= ${times_to_rotate}; i++)); do
transpose+=",transpose=1"
done
# 90 degrees clockwise: transpose=1
# 90 degrees counterclockwise: transpose=2
# `-c:a copy` - ensures audio (if present) is copied without re-encoding (not applicable for images, but safe to include).
ffmpeg -i ${filename} -vf ${transpose} -c:a copy ${basename_without_ext}_rot.${extension}
}
this_file_name=`basename "$0"`
if [ $# -lt 1 ]; then
echo "error: path to file is missing."
echo "usage: '$this_file_name [path_to_file] ([times_to_rotate_90_degrees (1)])'"
exit 1
fi
rotate $1 $2