I have created a bash-script with gmic 3.7.0 using Ubuntu 24.94
Please use it only if you are experienced with the bash and if you check my commands before. I know some parts could be better coded, but it works for me for testing.
It works for me with my pc without problems, but this doesn’t mean it works with your pc.
IMHO the only dangerous command could be
rm -r "$albumdir/upscale-$albumdirshort"
It was coded a little bit strange since upscaledir exists
upscaledir="$albumdir/upscale-$albumdirshort"
The advantage is, if a variable gets empty then there is something to delete, which doesn’t exist probably.
If you are angry, make the line with “rm” as a comment and put # before it. Then you have to delete the upscaledir manually.
I called it upscale-script.sh
In a terminal run:
Example:
upscale-script.sh /path-to-pictures/lagos/
Avoid spaces in the path, not sure it all is quoted correctly.
What the script does:
creates a tgz-backupfile of the dir, if the backupfile doesn’t exist
Upscaling options with gmic must be defined for every image-dir. So you can/must define for every image-dir different upscaling options
For now there are 6 different options pre-defined and can be changed easily. Simply make “optionX” a comment with # before and it will not be computed
The name of the upscaled file has a part of the options included.
The original metadata are (more or less) restored with exiftool
The result files look something like this:
upscale-lagos$ ls -1
lagos1.jpg
lagos1_patch2x_0-0+richardsonlucy_1.3-4-1-1.jpg
lagos1_patch2x_0-0+richardsonlucy_1.4-8-1-1.jpg
lagos2.jpg
lagos2_patch2x_0-0+richardsonlucy_1.3-4-1-1.jpg
lagos2_patch2x_0-0+richardsonlucy_1.4-8-1-1.jpg
So the original file was copied to the upscale-dir, so it is easier to compare.
The idea is to get files with different upscales automatically and you delete the files which you don’t like. To upscale hundred of files with gimp manually would take days. With the new filename you have an idea how you should change the options maybe.
# #!/bin/bash
if [ -z "$1" ]; then
echo
echo "enter image dir as argument"
echo "start script with image dir again"
echo "used with gmic v.3.7.0"
echo
exit
fi
if [ -d "$1" ]; then
cd "$1"
albumdir=$(pwd)
albumdirshort=$(basename "$albumdir" | sed -e 's/.*/\L&/' -e 's/ /_/g')
backupfile="$albumdir/$albumdirshort.tgz"
upscaledir="$albumdir/upscale-$albumdirshort"
echo
It
# removing existing upscale-files
if [ -d "$upscaledir" ] ; then
# danger of using an empty variable with rm, therefore
rm -r "$albumdir/upscale-$albumdirshort"
echo "deleted existing <$upscaledir>"
fi
mkdir -p "$upscaledir"
echo "created empty <$upscaledir>"
echo
else
echo "image dir not found"
echo "enter a valid image dir"
echo "start script with image dir again"
echo
exit
fi
if [ ! -f "$backupfile" ] ; then
time tar -cvzf "$backupfile" "$albumdir"
else
echo
echo "$backupfile exists"
echo "maybe this is an old and not uptodate backup!"
echo
fi
# preferred albumnames in lowercase without spaces
# no tests have been made with files using spaces
option1=
option2=
option3=
option4=
option5=
option6=
# looks like gmic-tile is broken with 3.7.0
# edit with your album-names
# define options which you want to use
if [ "$albumdirshort" = "tenerife" ] ; then
# garagecoder
option1="fx_gcd_upscale_patch2x 0,0"
option_filename1=$(echo "$option1" | cut -f4 -d"_" | sed -e 's/ /_/g' -e 's/,/-/g')
#option2="fx_gcd_upscale_patch2x 0,1"
option_filename2=$(echo "$option2" | cut -f4 -d"_" | sed -e 's/ /_/g' -e 's/,/-/g')
option3="fx_gcd_upscale_patch2x 2,0"
option_filename3=$(echo "$option3" | cut -f4 -d"_" | sed -e 's/ /_/g' -e 's/,/-/g')
#option4="fx_gcd_upscale_patch2x 2,1"
option_filename4=$(echo "$option4" | cut -f4 -d"_" | sed -e 's/ /_/g' -e 's/,/-/g')
# garagecoder + richardsonlucy
option5="fx_gcd_upscale_patch2x 2,0 fx_unsharp_richardsonlucy 1.2,2,1,1"
option_filename5=$(echo "$option5" | cut -f4 -d"_" | sed -e 's/ fx//')+$(echo "$option5" | cut -f6 -d"_")
option_filename5=$(echo "$option_filename5" | sed -e 's/ /_/g' -e 's/,/-/g')
option6="fx_gcd_upscale_patch2x 2,0 fx_unsharp_richardsonlucy 1.3,3,1,1"
option_filename6=$(echo "$option6" | cut -f4 -d"_" | sed -e 's/ fx//')+$(echo "$option6" | cut -f6 -d"_")
option_filename6=$(echo "$option_filename6" | sed -e 's/ /_/g' -e 's/,/-/g')
elif [ "$albumdirshort" = "lagos" ] ; then
# garagecoder
#option1="fx_gcd_upscale_patch2x 0,0"
option_filename1=$(echo "$option1" | cut -f4 -d"_" | sed -e 's/ /_/g' -e 's/,/-/g')
#option2="fx_gcd_upscale_patch2x 0,1"
option_filename2=$(echo "$option2" | cut -f4 -d"_" | sed -e 's/ /_/g' -e 's/,/-/g')
#option3="fx_gcd_upscale_patch2x 2,0"
option_filename3=$(echo "$option3" | cut -f4 -d"_" | sed -e 's/ /_/g' -e 's/,/-/g')
#option4="fx_gcd_upscale_patch2x 2,1"
option_filename4=$(echo "$option4" | cut -f4 -d"_" | sed -e 's/ /_/g' -e 's/,/-/g')
# garagecoder + richardsonlucy
option5="fx_gcd_upscale_patch2x 0,0 fx_unsharp_richardsonlucy 1.3,4,1,1"
option_filename5=$(echo "$option5" | cut -f4 -d"_" | sed -e 's/ fx//')+$(echo "$option5" | cut -f6 -d"_")
option_filename5=$(echo "$option_filename5" | sed -e 's/ /_/g' -e 's/,/-/g')
option6="fx_gcd_upscale_patch2x 0,0 fx_unsharp_richardsonlucy 1.4,8,1,1"
option_filename6=$(echo "$option6" | cut -f4 -d"_" | sed -e 's/ fx//')+$(echo "$option6" | cut -f6 -d"_")
option_filename6=$(echo "$option_filename6" | sed -e 's/ /_/g' -e 's/,/-/g')
else
echo
echo "no gmic-options defined for <$albumdirshort>"
echo "edit script and define options"
echo
exit
fi
# assuming no files in subdirs
# keeping original size in Makernotes
find "$albumdir" -maxdepth 1 -type f -regex ".*\(jpg$\|jpeg$\)" -print0 | sort | while read -d $'\0' image_file_source
do
# doing a lot for filenames
image_file_source_short=$(basename "$image_file_source")
image_file_without_extension=$(echo "$image_file_source_short" | sed -e 's/\.[^.]*$//')
echo
echo "============================================"
echo
echo "upscaling $image_file_source_short"
# for comparison
cp "$image_file_source" "$upscaledir"
image_file_upscaled1="$upscaledir""/$image_file_without_extension""_$option_filename1".jpg
image_file_upscaled2="$upscaledir""/$image_file_without_extension""_$option_filename2".jpg
image_file_upscaled3="$upscaledir""/$image_file_without_extension""_$option_filename3".jpg
image_file_upscaled4="$upscaledir""/$image_file_without_extension""_$option_filename4".jpg
image_file_upscaled5="$upscaledir""/$image_file_without_extension""_$option_filename5".jpg
image_file_upscaled6="$upscaledir""/$image_file_without_extension""_$option_filename6".jpg
if [ -n "$option1" ] ; then
echo
echo "----------------------"
echo "$option1"
echo
time gmic -i "$image_file_source" -$option1 -o "$image_file_upscaled1"
exiftool -q -q -m -overwrite_original -tagsfromfile "$image_file_source" -all:all -tagsfromfile "$image_file_upscaled1" -all:all "$image_file_upscaled1"
new_image_width=$(exiftool -q -q -s -s -s -FILE:ImageWidth "$image_file_upscaled1")
new_image_height=$(exiftool -q -q -s -s -s -FILE:ImageHeight "$image_file_upscaled1")
exiftool -overwrite_original -EXIF:ExifImageWidth="$new_image_width" -EXIF:ExifImageHeight="$new_image_height" "$image_file_upscaled1"
fi
if [ -n "$option2" ] ; then
echo
echo "----------------------"
echo "$option2"
echo
time gmic -i "$image_file_source" -$option2 -o "$image_file_upscaled2"
exiftool -q -q -m -overwrite_original -tagsfromfile "$image_file_source" -all:all -tagsfromfile "$image_file_upscaled2" -all:all "$image_file_upscaled2"
new_image_width=$(exiftool -q -q -s -s -s -FILE:ImageWidth "$image_file_upscaled2")
new_image_height=$(exiftool -q -q -s -s -s -FILE:ImageHeight "$image_file_upscaled2")
exiftool -overwrite_original -EXIF:ExifImageWidth="$new_image_width" -EXIF:ExifImageHeight="$new_image_height" "$image_file_upscaled2"
fi
if [ -n "$option3" ] ; then
echo
echo "----------------------"
echo "$option3"
echo
time gmic -i "$image_file_source" -$option3 -o "$image_file_upscaled3"
exiftool -q -q -m -overwrite_original -tagsfromfile "$image_file_source" -all:all -tagsfromfile "$image_file_upscaled3" -all:all "$image_file_upscaled3"
new_image_width=$(exiftool -q -q -s -s -s -FILE:ImageWidth "$image_file_upscaled3")
new_image_height=$(exiftool -q -q -s -s -s -FILE:ImageHeight "$image_file_upscaled3")
exiftool -overwrite_original -EXIF:ExifImageWidth="$new_image_width" -EXIF:ExifImageHeight="$new_image_height" "$image_file_upscaled3"
fi
if [ -n "$option4" ] ; then
echo
echo "----------------------"
echo "$option4"
echo
time gmic -i "$image_file_source" -$option4 -o "$image_file_upscaled4"
exiftool -q -q -m -overwrite_original -tagsfromfile "$image_file_source" -all:all -tagsfromfile "$image_file_upscaled4" -all:all "$image_file_upscaled4"
new_image_width=$(exiftool -q -q -s -s -s -FILE:ImageWidth "$image_file_upscaled4")
new_image_height=$(exiftool -q -q -s -s -s -FILE:ImageHeight "$image_file_upscaled4")
exiftool -overwrite_original -EXIF:ExifImageWidth="$new_image_width" -EXIF:ExifImageHeight="$new_image_height" "$image_file_upscaled4"
fi
if [ -n "$option5" ] ; then
echo
echo "----------------------"
echo "$option5"
echo
time gmic -i "$image_file_source" -$option5 -o "$image_file_upscaled5"
exiftool -q -q -m -overwrite_original -tagsfromfile "$image_file_source" -all:all -tagsfromfile "$image_file_upscaled5" -all:all "$image_file_upscaled5"
new_image_width=$(exiftool -q -q -s -s -s -FILE:ImageWidth "$image_file_upscaled5")
new_image_height=$(exiftool -q -q -s -s -s -FILE:ImageHeight "$image_file_upscaled5")
exiftool -overwrite_original -EXIF:ExifImageWidth="$new_image_width" -EXIF:ExifImageHeight="$new_image_height" "$ioption6mage_file_upscaled5"
fi
if [ -n "$option6" ] ; then
echo
echo "----------------------"
echo "$option6"
echo
time gmic -i "$image_file_source" -$option6 -o "$image_file_upscaled6"
exiftool -q -q -m -overwrite_original -tagsfromfile "$image_file_source" -all:all -tagsfromfile "$image_file_upscaled6" -all:all "$image_file_upscaled6"
new_image_width=$(exiftool -q -q -s -s -s -FILE:ImageWidth "$image_file_upscaled6")
new_image_height=$(exiftool -q -q -s -s -s -FILE:ImageHeight "$image_file_upscaled6")
exiftool -overwrite_original -EXIF:ExifImageWidth="$new_image_width" -EXIF:ExifImageHeight="$new_image_height" "$image_file_upscaled6"
fi
done