🎄 GitHub Actions Advent Calendar

moon indicating dark mode
sun indicating light mode

Day 2: Optimizing Images

December 02, 2019

When adding images into projects, they sometimes include a lot of metadata or are saved in formats that have large file sizes by default. The folks over at Calibre created an action called image-actions which provides a way to automatically compress JPGs, PNGs, and WebP images.

Example Usage

As in their example, a use case is to optimize images in Pull Requests:

name: Compress images
on: pull_request
jobs:
build:
name: calibreapp/image-actions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: calibreapp/image-actions
uses: docker://calibreapp/github-image-actions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

so then if you had this in a project and created a PR that added some images, it would optimize them, make a new commit to the PR, and then add a comment saying which ones were compressed.

Comment in PR showing images compressed