diff --git a/.github/ISSUE_TEMPLATE/1-addTokenForm.yml b/.github/ISSUE_TEMPLATE/1-addTokenForm.yml index 66abd1e5..77cea4a9 100644 --- a/.github/ISSUE_TEMPLATE/1-addTokenForm.yml +++ b/.github/ISSUE_TEMPLATE/1-addTokenForm.yml @@ -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 diff --git a/.github/ISSUE_TEMPLATE/2-addImageForm.yml b/.github/ISSUE_TEMPLATE/2-addImageForm.yml index 5ba77f4a..06986df9 100644 --- a/.github/ISSUE_TEMPLATE/2-addImageForm.yml +++ b/.github/ISSUE_TEMPLATE/2-addImageForm.yml @@ -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 diff --git a/.github/workflows/optimizeImage.yml b/.github/workflows/optimizeImage.yml index a9bbb58e..68f04ba2 100644 --- a/.github/workflows/optimizeImage.yml +++ b/.github/workflows/optimizeImage.yml @@ -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