Skip to content
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

feat: add support for SVG image files #694

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1-addTokenForm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ body:
id: imageUrl
attributes:
label: Image URL
description: Ideally a 256x256 PNG file. But we'll take care of optimizing it later.
description: Ideally a 256x256 PNG or SVG file. But we'll take care of optimizing it later.
placeholder: https://gateway.pinata.cloud/ipfs/Qme9B6jRpGtZsRFcPjHvA5T4ugFuL4c3SzWfxyMPa59AMo
validations:
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/2-addImageForm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ body:
id: imageUrl
attributes:
label: Image URL
description: Ideally a 256x256 PNG file. But we'll take care of optimizing it later.
description: Ideally a 256x256 PNG or SVG file. But we'll take care of optimizing it later.
placeholder: https://gateway.pinata.cloud/ipfs/Qme9B6jRpGtZsRFcPjHvA5T4ugFuL4c3SzWfxyMPa59AMo
validations:
required: true
31 changes: 22 additions & 9 deletions .github/workflows/optimizeImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,32 @@ jobs:
- name: Download image
run: curl -o image.png "${{ inputs.url }}"

- name: Install imagemagick
run: sudo apt install imagemagick
- name: Install dependencies
run: sudo apt install imagemagick rsvg-convert

- name: Check image size and optimize if necessary
- name: Optimze image
run: |
should_optimize=$(identify -format "%[fx:w>256 && h>256]" image.png)
image_type=$(identify -format "%m" image.png)

if [ "$should_optimize" = "1" ]; then
echo "Optimizing image"
convert image.png -depth 7 -resize 256x -posterize 24 output.png
if [[ "$image_type" == "SVG" ]]; then
echo "Editing SVG properties"
# Update the height and width attributes directly in the SVG file
sed -i 's/height="[0-9]*"/height="256"/; s/width="[0-9]*"/width="256"/' image.png
# Convert the edited SVG to PNG
rsvg-convert -o output.png image.png
elif [[ "$image_type" == "PNG" ]]; then
should_optimize=$(identify -format "%[fx:w>256 && h>256]" image.png)

if [ "$should_optimize" = "1" ]; then
echo "Optimizing PNG image"
convert image.png -depth 7 -resize 256x -posterize 24 output.png
else
echo "Image is already small enough, moving to output.png"
mv image.png output.png
fi
else
echo "Image is already small enough, moving to output.png"
mv image.png output.png
echo "Error: Unsupported image type: $image_type" >&2
exit 1
fi

- name: Upload img
Expand Down
Loading