Skip to content

Instantly share code, notes, and snippets.

@gullinbursti
Last active May 11, 2023 19:10
Show Gist options
  • Save gullinbursti/e79cd924cee2fd42e2a52d8a990cc037 to your computer and use it in GitHub Desktop.
Save gullinbursti/e79cd924cee2fd42e2a52d8a990cc037 to your computer and use it in GitHub Desktop.
Conversion functions to downgrade iPhone SE 2nd Gen media types
#!/bin/bash
function heicSE() {
#-- org heic arch
local bkup_file=~/Pictures/heic.tar
#-- args 1: scale (50%) // 2: type (JPG) // 3: quality (80%)
local dims_per=50
[[ ! -z "$1" ]] && dims_per=$1
local img_ext="jpg"
[[ ! -z "$2" ]] && img_ext="$2"
local qual_per=80
[[ ! -z "$3" ]] && qual_per=$3
#-- move *.HEIC to *.heic
printf "Normalizing HEIC extensions...\n"
for f in *.HEIC; do printf " %s --> %s ..." "$f" "${f%.*}.heic"
mv "$f" "${f%.*}.heic"
echo
done ; echo
#-- heic file size // append on tar
printf "HEIC total bytes: %s\n\n" "`du -ch *.heic | sed -n '$p;' | awk '{print $1}'`"
printf "Backing up src *.heic ...\n"
tar -rvf $bkup_file *.heic
echo
#-- calc # to convert
cnt=0
tot=$(ls -1 *.heic | wc -l | awk '{print $1}')
printf "Converting %d to %s w/ %3d%% quality @ %3d%% size...\n" $tot "`<<<$img_ext tr '[:lower:]' '[:upper:]'`" $qual_per $dims_per
#-- convert // copy exif // retouch date
for f in *.heic; do cnt=$(( cnt+1 ))
f2="${f%.*}.${img_ext}"
printf "(%02d/%02d) %s [%-4s]-=/> %s ..." $cnt $tot "$f" "`du -h "$f" | awk '{print $1}'`" "$f2"
convert "$f" -scale "${dims_per}%" -quality "${qual_per}%" "$f2"
printf "[%s] // EXIF & touching..." "`du -h "$f2" | awk '{print $1}'`"
exiftool -quiet -quiet -ignoreMinorErrors -preserve -overwrite_original_in_place -progress: -tagsFromFile "$f" "$f2"
touch -r "$f" "$f2"
echo
done ; echo
#-- delete *.heic
printf "Removing src *.heic ..."
rm -f *.heic
echo
#-- show dir date asc // combined file sizes // page exif
ls -plah -tr
printf "%s total bytes: %s\n\n" "`<<<$img_ext tr '[:lower:]' '[:upper:]'`" "`du -ch *.${img_ext} | sed -n '$p;' | awk '{print $1}'`"
exiftool -fast -all -g -U -json -progress: -ext "$img_ext" . | jq -C '.' | less
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment