Skip to content

Commit

Permalink
ignore bad images in image optimisation script
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Aug 10, 2024
1 parent 08adfef commit af0d724
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions scripts/optimise-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ sudo apt -y install optipng advancecomp jpegoptim
# Function to optimise PNGs
optimise_png() {
local file="$1"
nice -n 10 ionice -c2 -n7 optipng -fix -o7 -preserve "$file"
nice -n 10 ionice -c2 -n7 advpng -z4 "$file"
touch -r "$file" "$file.optimised" # Set .optimised file's modification time to the original file's time
chmod 600 "$file.optimised" # Restrict permissions to owner only
if nice -n 10 ionice -c2 -n7 optipng -fix -o7 -preserve "$file"; then
if nice -n 10 ionice -c2 -n7 advpng -z4 "$file"; then
touch -r "$file" "$file.optimised" # Set .optimised file's modification time to the original file's time
chmod 600 "$file.optimised" # Restrict permissions to owner only
else
echo "Error: Failed to process $file with advpng. Skipping."
fi
else
echo "Error: Failed to process $file with optipng. Skipping."
fi
}

# Function to optimise JPEGs
optimise_jpeg() {
local file="$1"
nice -n 10 ionice -c2 -n7 jpegoptim --strip-none "$file"
touch -r "$file" "$file.optimised" # Set .optimised file's modification time to the original file's time
chmod 600 "$file.optimised" # Restrict permissions to owner only
if nice -n 10 ionice -c2 -n7 jpegoptim --strip-none "$file"; then
touch -r "$file" "$file.optimised" # Set .optimised file's modification time to the original file's time
chmod 600 "$file.optimised" # Restrict permissions to owner only
else
echo "Error: Failed to process $file with jpegoptim. Skipping."
fi
}

# Clean up orphaned .optimised files
Expand Down

0 comments on commit af0d724

Please sign in to comment.