Skip to content

Commit

Permalink
add flair validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fitztrev committed Dec 9, 2023
1 parent 27900f3 commit 5c39ff1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/flair.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Validate Flair

on:
push:
paths:
- 'public/flair/**'
pull_request:
paths:
- 'public/flair/**'

jobs:
validate-flair:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./bin/validate-flair public/flair/img/
50 changes: 50 additions & 0 deletions bin/validate-flair
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash -e

if [ -z "$1" ]; then
echo "Usage: $0 <path/to/flair/dir>"
exit 1
fi

exit_code=0

for img_file in "$1"/*; do
if [[ ! "$img_file" =~ \.webp$ ]]; then
echo "Not a WEBP: $img_file"
exit_code=1
continue
fi

dimensions=$(identify -format "%wx%h" "$img_file")

width=$(echo "$dimensions" | cut -d 'x' -f 1)
height=$(echo "$dimensions" | cut -d 'x' -f 2)

if [ "$width" -ne "$height" ]; then
echo "Not square: $img_file ($dimensions)"
exit_code=1

echo "Converting to square..."
max_dimension=$((width > height ? width : height))
convert "$img_file" -gravity center -background transparent -extent "${max_dimension}x${max_dimension}" "$img_file"
fi

if [ "$width" -lt 60 ] || [ "$width" -gt 100 ]; then
echo "Not between 60-100px: $img_file ($dimensions)"
exit_code=1

echo "Resizing to 100px..."
convert "$img_file" -resize 100x100 "$img_file"
fi

# animated WEBPs contain the string "ANMF" in the file
if grep -q "ANMF" "$img_file"; then
echo "Animated: $img_file"
exit_code=1
fi
done

if [ "$exit_code" -eq 0 ]; then
echo "✅ Images are OK"
fi

exit $exit_code

0 comments on commit 5c39ff1

Please sign in to comment.