From 21c1b3c1a7156748fa653135d91a5dcc8d8ec05b Mon Sep 17 00:00:00 2001 From: "committer@tuxwarrior" Date: Wed, 4 Mar 2026 11:43:52 -0500 Subject: [PATCH] + imgResize.sh & rotate.sh --- dots/bash/.bashrc | 14 +------------ dots/bash/obsolete.bashrc | 11 ++++++++++ dots/bin/imgResize.sh | 39 ++++++++++++++++++++++++++++++++++ dots/bin/rotate.sh | 44 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 13 deletions(-) create mode 100755 dots/bin/imgResize.sh create mode 100755 dots/bin/rotate.sh diff --git a/dots/bash/.bashrc b/dots/bash/.bashrc index e000998..2c4ff57 100644 --- a/dots/bash/.bashrc +++ b/dots/bash/.bashrc @@ -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 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 \ diff --git a/dots/bash/obsolete.bashrc b/dots/bash/obsolete.bashrc index 40a283d..4b90d7c 100644 --- a/dots/bash/obsolete.bashrc +++ b/dots/bash/obsolete.bashrc @@ -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}" +# } diff --git a/dots/bin/imgResize.sh b/dots/bin/imgResize.sh new file mode 100755 index 0000000..bc0b993 --- /dev/null +++ b/dots/bin/imgResize.sh @@ -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 diff --git a/dots/bin/rotate.sh b/dots/bin/rotate.sh new file mode 100755 index 0000000..d90a651 --- /dev/null +++ b/dots/bin/rotate.sh @@ -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