• Stars
    star
    269
  • Rank 152,662 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A command-line interface (CLI) utility written in pure Python to help you reduce the file size of images.

Optimize Images Github commits (since latest release) PyPI PyPI - Downloads

A command-line interface (CLI) utility written in pure Python to help you reduce the file size of images.

This application is intended to be pure Python, with no special dependencies besides Pillow, therefore ensuring compatibility with a wide range of systems, including iPhones and iPads running Pythonista 3. If you don't have the need for such a strict dependency management, you will probably be better served by any several other image optimization utilities that are based on some well known external binaries.

Some aditional features can be added which require the presence of other third-party packages that are not written in pure Python, but those packages and the features depending on them should be treated as optional.

optimize-images_screenshot

If you were just looking for the graphical user interface (GUI) version of this application, it's a separate project: Optimize Images X.

Full Documentation:

Please refer to the above links if you want to know about all the options available in this application. For a quick intro, just to get a feeling of what it can do, please keep reading below.

Installation and dependencies:

To install and run this application, you need to have a working Python 3.6+ installation. We try to keep the external dependencies at a minimum, in order to keep compatibility with different platforms, including Pythonista on iOS. At this moment, we require:

  • Pillow==8.2.0
  • piexif==1.1.3
  • watchdog==2.1.2

The easiest way to install it in a single step, including any dependencies, is by using this command:

pip3 install pillow optimize-images

If you are able to swap Pillow with the faster version Pillow-SIMD, you should be able to get a considerably faster speed. For that reason, we provide, as a friendly courtesy, an optional shell script (replace_pillow__macOS.sh) to replace Pillow with the faster Pillow-SIMD on macOS. Please notice, however, that it usually requires a compilation step and it was not throughly tested by us, so your mileage may vary.

You can also use this application on iOS, using an called Pythonista 3 (which is, among other things, a very nice environment for developing and/or running pure Python applications on iOS). Please check the detailed install procedure full in the user documentation.

How to use

The most simple form of usage is to type a simple command in the shell, passing the path to an image or a folder containing images as an argument. The optional -nr or --no-recursion switch argument tells the application not to scan recursively through the subdirectories.

By default, this utility applies lossy compression to JPEG files using a variable quality setting between 75 and 80 (by Pillow's scale), that is dynamically determined for each image according to the amount of change caused in its pixels, then it removes any EXIF metadata, tries to optimize each encoder's settings for maximum space reduction and applies the maximum ZLIB compression on PNG.

You must explicitly pass it a path to the source image file or to the directory containing the image files to be processed. By default, it will scan recursively through all subfolders and process any images found using the default or user-provided settings, replacing each original file by its processed version if its file size is smaller than the original.

If no space savings were achieved for a given file, the original version will be kept instead.

There are many other features and command-line options, like downsizing, keeping EXIF data, color palete reduction, PNG to JPEG conversion. Please check the docs for further information.

DISCLAIMER:
Please note that the operation is done DESTRUCTIVELY, by replacing the original files with the processed ones. You definitely should duplicate the source file or folder before using this utility, in order to be able to recover any eventual damaged files or any resulting images that don't have the desired quality.

Basic usage

Try to optimize a single image file:

optimize-images filename.jpg

Try to optimize all image files in current working directory and all of its subdirectories:

optimize-images ./

Try to optimize all image files in current working directory, without recursion:

optimize-images -nr ./
optimize-images --no-recursion ./

Getting help

To check the list of available options and their usage, you just need to use one of the following commands:

optimize-images -h
optimize-images --help

Did you find a bug or do you have a suggestion?

Please let me know, by opening a new issue or a pull request.

More Repositories

1

optimize-images-x

A desktop app written in Python, that exposes and unlocks the full power of Optimize Images in a nice graphical user interface, to help you reduce the file size of images.
Python
26
star
2

Count-files

A CLI utility written in Python to help you count files, grouped by extension, in a directory. By default, it will count files recursively in current working directory and all of its subdirectories, and will display a table showing the frequency for each file extension (e.g.: .txt, .py, .html, .css) and the total number of files found.
Python
22
star
3

PT-Tracking

Aplicação para registo e acompanhamento de encomendas da CTT Expresso, automatiza a consulta online do estado de tracking para várias remessas e mantém um registo dos pagamentos referentes aos envios à cobrança. As remessas que requerem atenção, devido a atrasos na entrega ou na receção do pagamento correspondente, bem como os cheques cuja data prevista de depósito se esteja a aproximar são destacadas na lista principal, por forma a permitir uma intervenção em conformidade. Adicionalmente, é mantido um histórico facilmente pesquisável de todas as remessas registadas na base de dados.
Python
19
star
4

RepService

Database application for in-store registering of warranty and service/repair processes in general. It enables store staff to keep an organized log of the products left for repair by costumers, their route during the process and the communications made. Processes that require special attention, for instance because of a delay in delivery or while waiting for an answer from the costumer, are highlighted in the main list, in order to allow proper intervention by the staff team.
Python
11
star
5

NiceTelescopePlanner

A simple cross-platform desktop utility for amateur astronomy hobbyists, written in Java. The aim is to provide an easy to use tool to help planning sky observation sessions, suggesting some of the interesting objects you may be able to watch at naked eye, or using amateur equipment (binoculars or small to medium size telescopes) in a given date/time and place.
Java
6
star
6

count-money

Um pequeno utilitário para ajudar a contar notas e moedas, calculando em tempo real o total correspondente.
Python
6
star
7

Learning_CPP_VisualStudio

Some introductory snippets written while learning Windows GUI programming in C++ using Microsoft Visual Studio. Mostly exercises suggested by a teacher or a book.
C++
5
star
8

The-No-Title-Tech-Blog

Exploring the amazing world of antigravity and other human made technologies.
HTML
3
star
9

Learning_COBOL

Some introductory snippets written while learning COBOL. Mostly exercises suggested by a teacher or a book.
COBOL
3
star
10

Learning_CSharp

Some introductory snippets written while learning C#. Mostly exercises suggested by a teacher or a book.
C#
3
star
11

EFAProg2019

Repositório git da turma EFA NS - Programador de Informática (2019-2020).
2
star
12

Learning_cpp

Some introductory snippets written while learning C++. Mostly exercises suggested by a teacher or a book.
C++
1
star
13

Learning_Node.js

Some exercises
1
star
14

Learning_Elixir

Just a few exercises and experiments
Elixir
1
star
15

Learning_JavaScript

Some exercises
HTML
1
star
16

Learning_Django

Nothing special here, just me following a Django tutorial.
Python
1
star
17

DjangoBlog

Exploring Django
JavaScript
1
star
18

npk-tictactoe

The amazing NPK TicTacToe game!
C++
1
star
19

Learning_Swift

Just a few exercises and experiments
Swift
1
star
20

victordomingos.com

CSS
1
star
21

Learning_DataScience

Some exercises on Data Science, Machine Learning, Deep Learning, done while reading through a couple of books and other sources.
Python
1
star
22

NPK-Backup

Um pequeno utilitário para automatizar a cópia de segurança de uma determinada pasta (por exemplo, cópias de segurança locais de bases de dados Filemaker, coleções de scripts e aplicações do Pythonista, etc.), criando arquivos zip individuais a partir de cada pasta principal na localização especificada e fazendo upload dos mesmos para a Dropbox. O programa mantém um registo simples, por forma a nao repetir as tarefas de compressão e upload já realizadas.
Python
1
star