Mon Apr 13 11:34:37 PDT 2015

Bash Script to Reduce the Size of TIF Files

I often find myself struggling with large files - particularly graphics files which are on their way to be coming efficiently organized pdf files. Here is an example script which examines the .tif files in the local directory and determines if a space saving can be made by reduce the number of colors stored to 256. It is not the most elegant bash script ever produced but it does the job.

#!/bin/sh

for FILE in *.tif
do
  echo $FILE
  tifftopnm $FILE | pnmquant 256 | pnmtotiff -lzw > tmp12
  SIZE1=`ls -ltra $FILE | awk '{print $5}'`
  SIZE2=`ls -ltra tmp12 | awk '{print $5}'`
  if [ $SIZE2 -lt $SIZE1 ]
  then
    echo "WE SHOULD USE THE REDUCED COLOR VERSION OF $FILE"
    du -sh $FILE
    du -sh tmp12
    mv tmp12 $FILE
  else
    echo "NO ACTION REQUIRED - NO SPACE SAVING ACHIEVED"
  fi
done
rm -f tmp12

Comments are closed


If you would like to get in touch with me, please mail zfs at themolecularuniverse.com

recent comments

Posted by ZFS | Permanent link | File under: bash
[StumbleUpon] [Digg] [Reddit] [Facebook] [Google]