Bulk resize images digitized at 400dpi to 300dpi
We had some pictures digitized at 400dpi as part of one of our project. If 400dpi might be interesting for preservation, the size of the generated files can be quite huge, considering the difference when viewing the JPG in a browser. So we decided to bulk resize the JPG sent by the digitization contractor before putting them online. From my understanding of DPI and linked concepts, based on a 400dpi scan, resizing it to be what it would have been if originally scanned at 300dpi means reducing the pictures dimensions by 75%.
The below bash script will deal with that :
#! /bin/bash
# Needed because our source folder contains spaces in the USB disk name
OIFS="$IFS"
IFS=$'\n'
# The folder containing the subfolders from the digitization
SRC_FOLDER=/media/smachefert/My\ Passport/4005_BU_BDX_MONTAIGNE_2017_LOT32/JPEG09_400dpi/*
# The folder where we want to create 300DPI files
OUT_FOLDER=/home/smachefert/Bureau/300DPI_LOT32/
for FOLDER in $SRC_FOLDER
do
# Si on est bien sur un sous-répertoire
if [ -d "$FOLDER" ]; then
# On crée le sous-répertoire de sortie s'il n'existe pas
BASE_FOLDER=`basename $FOLDER`
if [ ! -d $OUT_FOLDER$BASE_FOLDER ]; then
echo ""
echo "Creation Folder "$OUT_FOLDER$BASE_FOLDER
mkdir $OUT_FOLDER$BASE_FOLDER
echo "Traitement dossier "$BASE_FOLDER
# On va récupérer toutes les images
for FILE in $FOLDER/*
do
BASE_FILE=`basename $FILE`
convert -quality 67 -resize 75% "$FILE" "$OUT_FOLDER$BASE_FOLDER/$BASE_FILE"
done
exit
else
echo "On passe "$BASE_FOLDER" qui existe déjà"
fi
else
echo "ERREUR "$FOLDER
fi
done
IFS="$OIFS"
It seems to work as expected but if you find that something is wrong, please contact me