-
Notifications
You must be signed in to change notification settings - Fork 28
70 lines (58 loc) · 1.9 KB
/
optimizeImage.yml
File metadata and controls
70 lines (58 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: OptimizeImage
# Input: chain, address, CID
# Steps:
# - resolve image/download it
# - optimize image: 256x256, remove metadata
# - upload new image to ipfs: name file <address>.png, upload it
# - return CID
on:
workflow_call:
inputs:
address:
required: true
type: string
url:
required: true
type: string
jobs:
execute:
runs-on: ubuntu-latest
steps:
- name: Download image
run: curl -o image.png "${{ inputs.url }}"
- name: Install dependencies
run: sudo apt install imagemagick librsvg2-bin
- name: Optimze image
run: |
image_type=$(identify -format "%m" image.png)
if [[ "$image_type" == "SVG" ]]; then
# Convert the SVG to PNG
rsvg-convert --width=256 --height=256 --keep-aspect-ratio -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 "Error: Unsupported image type: $image_type" >&2
exit 1
fi
- name: Upload img
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.address }}
path: output.png
retention-days: 1
- name: Report error
if: ${{ failure() }}
uses: peter-evans/close-issue@v2
with:
comment: |
Failed to optimize image
Check you provided a proper image file and try again in a new issue
If the issue persists, create a bug report
cc @cowprotocol/frontend