Skip to content

A GitHub action that automatically compresses SVG, PNG, JPG, GIF, WEBP, and AVIF in pull requests. Free and open-source alternative to imgbot.

License

Notifications You must be signed in to change notification settings

cadamsdev/image-optimizer-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Optimizer Action

contributions welcome License: GPL v3 GitHub Tag

A GitHub action that automatically compresses images in pull requests. Free and open-source alternative to imgbot.

✨ Features

✅ Fast, efficient and near-lossless compression

✅ Supports compressing SVG, PNG, JPG, GIF, WEBP, and AVIF

✅ Can export PNG, JPG and GIF to WEBP

✅ Can export PNG, JPG and WEBP to AVIF

✅ Highly customizable

✅ Supports GitHub Enterprise

View On GitHub Marketplace

This tool is completely free. If you enjoy the tool please help support us.

"Buy Me A Coffee"

📚 Table of Contents

  1. Media
  2. Usage
  3. Configuration
  4. Permissions

🖼️ Media

Screenshot 2024-11-25 231001

🚀 Usage

Pull request workflow

Create file .github/workflows/image-optimizer.yml

name: Compress Images

on:
  pull_request:
    paths:
      - '**/*.svg'
      - '**/*.png'
      - '**/*.jpg'
      - '**/*.jpeg'
      - '**/*.gif'
      - '**/*.webp'
      - '**/*.avif'

jobs:
  build:
    if: github.event.pull_request.head.repo.full_name == github.repository
    name: cadamsdev/image-optimizer-action
    permissions: write-all
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Compress Images
        id: compress-images
        uses: cadamsdev/image-optimizer-action@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

Manual Workflow

Create file .github/workflows/image-optimizer-manual.yml

name: Compress Images (Manual)

on: workflow_dispatch

jobs:
  build:
    name: cadamsdev/image-optimizer-action
    permissions: write-all
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Compress Images
        id: compress-images
        uses: cadamsdev/image-optimizer-action@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Create New Pull Request If Needed
        if: steps.compress-images.outputs.markdown_report != ''
        uses: peter-evans/create-pull-request@v5
        with:
          title: Compressed Images
          branch-suffix: timestamp
          commit-message: Compressed Images
          body: ${{ steps.compress-images.outputs.markdown_report }}

🔧 Configuration

e.g

with:
  github-token: ${{ secrets.GITHUB_TOKEN }}
  export-webp: true
  export-avif: true
  replace-original-after-export-webp: true
  ignore-paths: |
    src/assets/images/some-dir/**
    src/assets/images/another-dir/**
Input Description Type Default
github-token The generated GitHub token string (required) ''
debug Enables verbose logging for easier debugging boolean false
compress-png Enables compressing PNGs boolean true
compress-svg Enables compressing SVGs boolean true
compress-jpg Enables compressing JPG / JPEGs boolean true
compress-webp Enables compressing WEBPs boolean true
compress-avif Enables compressing AVIFs boolean true
export-webp Converts PNG, JPG / JPEG into WEBP boolean false
export-avif Converts PNG, JPG / JPEG, WEBP into AVIF boolean false
replace-original-after-export-webp Replace original files after exporting WebP files boolean false
ignore-paths Paths of globs to prevent from processing string[] node_modules/**

🔒 Permissions

Make sure to check "Allow GitHub Actions to create and approve pull requests" if you're using the manual workflow.

Screenshot 2024-11-25 230654

About

A GitHub action that automatically compresses SVG, PNG, JPG, GIF, WEBP, and AVIF in pull requests. Free and open-source alternative to imgbot.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published