Skip to content

Add param to only squash single image #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions scripts/squash-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
set -e

# pip install pillow
python3 scripts/thumbnail-images.py
if [ ! -z $1 ]
then
python3 scripts/thumbnail-images.py --inspec $1
else
python3 scripts/thumbnail-images.py
fi

# https://pmt.sourceforge.io/pngcrush/
# On Mac: brew install pngcrush
Expand All @@ -11,4 +16,9 @@ python3 scripts/thumbnail-images.py
# -ow Overwrite
# -brute Use brute-force: try 176 different methods

find . -iname '*.png' -exec pngcrush -ow -brute {} \;
if [ ! -z $1 ]
then
pngcrush -ow -brute $1
else
find . -iname '*.png' -exec pngcrush -ow -brute {} \;
fi
8 changes: 8 additions & 0 deletions scripts/thumbnail-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
"""
Thumbnail images to a maximum of 320px wide and 160px high
"""
import argparse
import glob

from PIL import Image # pip install pillow

max_size = 320, 160

parser = argparse.ArgumentParser(
description="Thumbnail images to a maximum size",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("--inspec", default="assets/*.png", help="Input file specification")
args = parser.parse_args()

for infile in glob.glob("assets/*.png"):
im = Image.open(infile)
if im.width <= max_size[0] and im.height <= max_size[1]:
Expand Down