Giter VIP home page Giter VIP logo

compressimages's Introduction

About

Bash script for bulk optimizing PNG/JPG files, quickly and reliably (includes download function, and GUI filepicker). It uses lossy compression, with barely noticeable differences except for filesize. Similar to tinypng.com.

Install

Download and install to /usr/local/bin/

wget https://raw.githubusercontent.com/644/compressimages/master/compressimages
sudo install -m 0755 compressimages /usr/local/bin/

Install dependencies

  • Ubuntu

    apt install -y jpegoptim pngquant parallel zenity imagemagick
    
  • Arch Linux

    pacman -Syu jpegoptim pngquant parallel zenity imagemagick
    

Run it with

compressimages [options] [files] [directories]
-0         use NUL as delimiter for stdin rather than newline
-t INT     threads to use (default: 16)
-p PATH    path to save compressed images (default: $HOME/compressed)
-nh        don't ignore directories starting with . or ..
-depth INT limit find's maxdepth to INT
-cc        convert images to JPG and PNG, compress, and keep the smallest file

Examples

Read from stdin

find . -type f -name '*.png' -print0 | compressimages -0 -p output/

It can detect whether it's a directory or file, or even a (s)ftp/http(s) URL

compressimages -depth 2 Downloads/ someimage.png Pictures/ https://website.com/image.png

Running

compressimages .

will recursively find and optimize all PNG/JPGs in the current directory, saving them in compressed/ by default

To open the zenity filepicker, just run

compressimages

To bulk convert all images (including webp,svg,etc) to both JPG and PNG, compress them, and keep the smallest file

compressimages -cc

To read filenames/folders/URLs from a .txt file

compressimages < images.txt

For directories, it will scan them for more images.

For files, it will check they are PNG/JPG before continuing to optimize them.

For URLs, it will attempt to match http(s)/sft(p)/file links to images, download them using wget, and add the downloaded file to the queue for testing if it's a JPG/PNG image.

Benchmark

For the benchmark I created 1,000 unique JPG and PNG images of ~2.0MB each. The script successfully compressed all 2,000 images in under a minute, saving 1.7GB of space total.

compress.mp4

Script to create the unique images

#!/usr/bin/env bash
for ((i=0; i<1000; i++)); do
	convert -size 1000x1000 xc:gray +noise gaussian "image-$i.png"
	convert -size 4000x1000 xc:gray +noise gaussian "image-$i.jpg"
done

Comparison

JPG

Screenshot taken with mpv of a 4K BluRay, uncompressed (7.0MB) scarface

Compressed version (889KB) scarface

PNG

Transparent image of the Rubik's Cube, uncompressed (79KB) rubik's

Compressed version (24KB) rubix

There are very small differences to the human eye in these examples, yet significant amounts of space was saved. Of course this example isn't 100% accurate (different test types on different images should be performed, like in: https://testimages.org/), but this should hopefully provide a rough idea as to what this script can do thanks to pngquant and jpegoptim.

More useful links: https://tinypng.com/ https://tinyjpg.com/

Dependencies

  • parallel
  • jpegoptim
  • pngquant
  • zenity (optional)
  • bash >= 4.0+

License

MIT

compressimages's People

Contributors

644 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.