Skip to content
forked from 9sako6/imgcmp

📷A GitHub Action that automatically optimizes images in your repository. Supported image file formats: JPEG, PNG, GIF, SVG, WEBP

License

Notifications You must be signed in to change notification settings

mthsmb/imgoptimizer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imgoptimizer v2.0.2

ci marketplace

This GitHub Actions optimizes images in your repository. You will receive a pull request with optimized images. This Github Actions is inspired by ImgBot.

A pull request example:

Usage

name: imgoptimizer
on:
  push:
    branches:
      - main
      - master
jobs:
  imgoptimizer:
    runs-on: ubuntu-latest
    steps:
      - uses: mthsmb/imgoptimizer@v2.0.2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

If you want to run this action only once a week, please add the following lines.

name: imgoptimizer
on:
  schedule:
    - cron: "0 0 * * 1" # Weekly build
jobs:
  imgoptimizer:
    runs-on: ubuntu-latest
    steps:
      - uses: mthsmb/imgoptimizer@v2.0.2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

Then, you will receive a pull request with optimized images every Monday at 0:00.

Configuration

Action inputs

Name Description Required
token GITHUB_TOKEN or a Personal access token (PAT). In a private repository, you have to use a PAT with enough permissions. See How to use a Personal Access Token. true
paths-ignore-regexp Regular expression for images' paths you don't want to compress. false

paths-ignore-regexp

imgoptimizer offers an ignore option. paths-ignore-regexp is regular expression for images' paths you don't want to compress.

Example:

name: imgoptimizer
on:
  push:
    branches:
      - main
      - master
jobs:
  imgoptimizer:
    runs-on: ubuntu-latest
    steps:
      - uses: mthsmb/imgoptimizer@v2.0.2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          paths-ignore-regexp: "(ignore/.*)|(public/.*)"

Action outputs

Name Description
pull-request-number A pull request number created by imgoptimizer.

Step outputs can be accessed as in the following example.

      - uses: mthsmb/imgoptimizer@v2.0.2
        id: imgoptimizer
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Check outputs
        run: |
          echo ${{ steps.imgoptimizer.outputs.pull-request-number }}

Supported image formats

  • JPEG/JPG
  • PNG
  • GIF
  • SVG
  • WEBP

Optimization tools

This bot uses these optimizers.

  • -m85: this will store the image with 85% quality
  • -o2: this sets the optimization level 2 (there is 0-7 optimization levels)
  • -O3: this sets the optimization level to Gifsicle's maximum

SVGO's default configuration will be used.

  • -q 75: cwebp's default optimization level

Benchmark

It took 34 sec to create the following PR.

Change Log

v2.0.2 (June 26, 2022)

v2.0.1 (April 10, 2022)

Bug fixes.

v2.0.0 (February 6, 2022)

There are breaking changes from version 1.0.1.

Author

mthsmb

About

📷A GitHub Action that automatically optimizes images in your repository. Supported image file formats: JPEG, PNG, GIF, SVG, WEBP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%