Giter VIP home page Giter VIP logo

Tinify In Folder

This Python script will tinify all the PNG and JPG images in a folder recursively.

Installation

You need Python 3 installed, and these modules:

  • os
  • time
  • glob
  • logging
  • argparse
  • tinify

All of these should already be installed since they are fairly standard, except for tinify. To install tinify, run pip install --upgrade tinify in a command line.

How to use it

The script is fairly simple.

Usage: tinifyImg.py [-h] -f FOLDER -k KEY [-d NUMBER_OF_DAYS] [-v] [--dry_run]

Arguments:

  • -h, --help: show this help message and exit
  • -f FOLDER, --folder FOLDER: Folder in which to look for images (required)
  • -k KEY, --key KEY: API key for Tinify service (required)
  • -d NUMBER_OF_DAYS, --days NUMBER_OF_DAYS: Only process the images that have been modified in the last NUMBER_OF_DAYS days (optional)
  • --dry_run: Will run the script but won't perform any compression
  • -v, --verbose: Will show complete output

The API key can be requested from the TinyPNG website.

Examples

Compress all the images in C:\Images that have been created or modified in the last 8 days:

python tinifyImg.py -f C:\Images -k dummyapikey123456789abcdefghijkl -d 8

Compress all the images in C:\Images\ToCompress:

python tinifyImg.py -f C:\Images\ToCompress -k dummyapikey123456789abcdefghijkl

Check how many images would be compress if we wanted to compress all the images in C:\Images\ToCompress:

python tinifyImg.py -f C:\Images\ToCompress -k dummyapikey123456789abcdefghijkl --dry_run

Notes

This is the kind of command output you can expect:

python tinifyImg.py -f C:\Images\ToCompress -k dummyapikey123456789abcdefghijkl --dry_run
[INFO] Running tinify script for images in a folder
[INFO] This is a dry run
[INFO] Remaining compressions: 428
[INFO] 36 images to compress, total size is 794.5 kb
[INFO] No errors during processing
[INFO] Total size is 794.5 kb, 0.0% lighter
[INFO] Remaining compressions: 428

The script has an hardcoded limit of 500 compressions per month, which corresponds to the free plan of TinyPNG.

License

This is free and unencumbered software released into the public domain. See LICENSE file for more information.

mohyeect's Projects

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.