Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

🖼 Optimize your images for web and local storage

License

Notifications You must be signed in to change notification settings

kerogenesis/image-optimizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Optimize your images for web and local storage

What does optimizer do?

The script uses TinyPNG smart lossy compression techniques to reduce the file size of your JPG/PNG files. By selectively decreasing the number of colors in the image, fewer bytes are required to store the data. The effect is nearly invisible but it makes a very large difference in file size.

Setup

  1. Download and install the latest version of Python
  2. Clone this repo
git clone https://github.com/kerogenesis/image-optimizer.git
  1. Create and activate virtual environment
python3.9 -m venv venv
source venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt

Initial setting

  1. Open settings.py in any text editor.
  2. Add a key from tinypng.com/developers to the API_KEY field.
  3. In the USER_INPUT_PATH field add a directory path with raw images.
  4. In the USER_OUTPUT_PATH field add the directory path with compressed files.

You can also select the option to delete raw images after compression.

Easy way to use

Linux/macOS

Create сompression.sh file with:

#!/usr/bin/env bash
source path/to/venv/bin/activate && python3.9 path/to/image_optimizer.py

Give this file permission to execute:

chmod +x сompression.sh

Move it to any place (e.g. desktop) and run it.

Windows

Create compression.bat file with:

@echo off
cmd /c "path\to\venv\Scripts\python.exe path\to\image_optimizer.py"

Move it to any place (e.g. desktop) and run it.

Important note

Remember the limit of 500 images per month on the free plan. You can change this at tinypng.com/dashboard/api