Skip to content

Instantly share code, notes, and snippets.

@jerieljan
Created April 10, 2017 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerieljan/b3e9f577535450db1a2f7beb18b27d72 to your computer and use it in GitHub Desktop.
Save jerieljan/b3e9f577535450db1a2f7beb18b27d72 to your computer and use it in GitHub Desktop.
A simple script for processing a directory of PNG images converted to JPG and compressed to Lepton and renamed into a sequence while retaining the modification dates.
#!/bin/bash
# This simple script processes screenshots taken with a PS3 and does multiple things:
# - Changes all PNG files to JPG using imagemagick
# - Compresses all files into Lepton-format images
# - Reapplies the original modification date for metadata retention.
# Prepare a file list, sorted by modification date.
rm FILELIST 2>/dev/null
ls -tdr1 *.png > FILELIST;
# Initialize necessary variables.
LIST=`cat FILELIST`
SEQ=1
if [ $# -eq 1 ]; then SEQ="$1"; fi
while read file;
do
# Track the current modified date
MDATE=`stat -c '%y' "$file"`
# Then apply the desired operations and apply the modified date onto the new file.
# If everything works without errors, remove the old file.
mv "$file" "${SEQ}.png"
mogrify -format jpg "${SEQ}.png"
rm "${SEQ}.png"
lepton "${SEQ}.jpg" "${SEQ}.jpg.lep"
touch -d "${MDATE}" "${SEQ}.jpg.lep"
rm "${SEQ}.jpg"
# Proceed to the next file and count up on the sequence.
SEQ=$(( $SEQ + 1 ))
done <FILELIST
# Clean up the temporary file list.
rm FILELIST 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment