This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/app/bin/home/photos_process

60 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
source /var/roothome/app/bin/home/shared.sh
if [ ! -f /mnt/storage/hot/.mount ]; then
echo mount hot storage
notify 'photos_process : hot storage not mounted'
exit 1
fi
cd /var/roothome/docker/cloud/data/data/cakee/files/media/photo
# convert png to jpg
echo "converting png to jpg.."
for img in $(ls *.png) $(ls *.PNG); do
echo "converting $img"
filename=${img%.*}
/usr/bin/convert "$filename.png" "$filename.jpg"
done
rm *.png *.PNG
# rename bad extensions
echo "renaming jpg.."
for img in $(ls *.jpeg) $(ls *.JPG) $(ls *.JPEG); do
echo "renaming $img"
filename=${img%.*}
mv "$img" "$filename.jpg"
done
# compress jpg
echo "compressing jpg.."
/usr/bin/mogrify -resize 2073600@ *.jpg
/usr/bin/jpegoptim --size=1000k *.jpg
# rename to hash
for file in *; do
if [[ -f "$file" ]]; then
extension="${file##*.}"
if [ -f "$file" ] && [ "$extension" != "$file" ]; then
new_name="${file%$extension}"
else
new_name="$file"
extension=""
fi
new_name=$(sha1sum "$file" | cut -d\ -f1)
if [[ "$extension" != "" ]]; then
new_name="${new_name,,}.$extension"
else
new_name="${new_name,,}"
fi
mv "$file" "$new_name"
fi
done
# move to images
echo "moving.."
total_photos=$(ls | wc -l)
mv *.jpg /mnt/storage/hot/media/family/dima/photo/
notify_silent "photos processed: $total_photos"