gullinbursti

Downgrade HEIC Scale + Quality

May 11th, 2023
1,062
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.45 KB | Source Code | 0 0
  1. function heicSE() { local bkup_file=~/Pictures/heic.tar ; 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 ; printf "Normalizing HEIC extensions...\n" ; for f in *.HEIC; do printf "  %s --> %s ..." "$f" "${f%.*}.heic" ; mv "$f" "${f%.*}.heic" ; echo ; done ; echo ; 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 ; 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 ; 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 ; printf "Removing src *.heic ..." ; rm -f *.heic ; echo ; 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 ;}
Advertisement
Comments
  • gullinbursti
    3 years (edited)
    # Bash 1.87 KB | 0 0
    1. ##-- --#--#--#-- De-minify --#--#--#-- --##
    2.  
    3. function heicSE() {
    4.   #-- org heic arch
    5.   local bkup_file=~/Pictures/heic.tar
    6.  
    7.   #-- args 1: scale (50%) // 2: type (JPG) // 3: quality (80%)
    8.   local dims_per=50
    9.   [[ ! -z "$1" ]] && dims_per=$1
    10.  
    11.   local img_ext="jpg"
    12.   [[ ! -z "$2" ]] && img_ext="$2"
    13.  
    14.   local qual_per=80
    15.   [[ ! -z "$3" ]] && qual_per=$3
    16.  
    17.   #-- move *.HEIC to *.heic
    18.   printf "Normalizing HEIC extensions...\n"
    19.   for f in *.HEIC; do printf "  %s --> %s ..." "$f" "${f%.*}.heic"
    20.     mv "$f" "${f%.*}.heic"
    21.     echo
    22.   done ; echo
    23.  
    24.   #-- heic file size // append on tar
    25.   printf "HEIC total bytes: %s\n\n" "`du -ch *.heic | sed -n '$p;' | awk '{print $1}'`"
    26.   printf "Backing up src *.heic ...\n"
    27.   tar -rvf $bkup_file *.heic
    28.   echo
    29.  
    30.   #-- calc # to convert
    31.   cnt=0
    32.   tot=$(ls -1 *.heic | wc -l | awk '{print $1}')
    33.   printf "Converting %d to %s w/ %3d%% quality @ %3d%% size...\n" $tot "`<<<$img_ext tr '[:lower:]' '[:upper:]'`" $qual_per $dims_per
    34.  
    35.   #-- convert // copy exif // retouch date
    36.   for f in *.heic; do cnt=$(( cnt+1 ))
    37.     f2="${f%.*}.${img_ext}"
    38.     printf "(%02d/%02d) %s [%-4s]-=/> %s ..." $cnt $tot "$f" "`du -h "$f" | awk '{print $1}'`" "$f2"
    39.     convert "$f" -scale "${dims_per}%" -quality "${qual_per}%" "$f2"
    40.     printf "[%s] // EXIF & touching..." "`du -h "$f2" | awk '{print $1}'`"
    41.     exiftool -quiet -quiet -ignoreMinorErrors -preserve -overwrite_original_in_place -progress: -tagsFromFile "$f" "$f2"
    42.     touch -r "$f" "$f2"
    43.     echo
    44.   done ; echo
    45.  
    46.   #-- delete *.heic
    47.   printf "Removing src *.heic ..."
    48.   rm -f *.heic
    49.   echo
    50.  
    51.   #-- show dir date asc // combined file sizes // page exif
    52.   ls -plah -tr
    53.   printf "%s total bytes: %s\n\n" "`<<<$img_ext tr '[:lower:]' '[:upper:]'`" "`du -ch *.${img_ext} | sed -n '$p;' | awk '{print $1}'`"
    54.   exiftool -fast -all -g -U -json -progress: -ext "$img_ext" . | jq -C '.' | less
    55. }
Add Comment
Please, Sign In to add comment