https://github.com/rootstrap/compress-s3-tinypng
Losslessly compresses and Optimizes PNG and JPG files. Uses TinyPNG API.
https://github.com/rootstrap/compress-s3-tinypng
Last synced: 10 months ago
JSON representation
Losslessly compresses and Optimizes PNG and JPG files. Uses TinyPNG API.
- Host: GitHub
- URL: https://github.com/rootstrap/compress-s3-tinypng
- Owner: rootstrap
- License: mit
- Created: 2018-08-14T21:36:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-08T17:44:17.000Z (about 4 years ago)
- Last Synced: 2025-04-05T18:51:59.854Z (10 months ago)
- Language: Python
- Size: 14.6 KB
- Stars: 6
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# compress-s3-tinypng
*Compress images in an S3 bucket using the TinyPNG API, and rewrite images with compressed versions*
This is a modified version of [s3-tinify][https://github.com/sc1f/s3-tinify].
It doesn't do any resizing, but only focuses on compressing/optimizing PNG and JPEG files.
To use this, we have to make sure that the bucket has the permissions: GetObjectTagging and PutObjectTagging.
It overwrites the existing versions.
LIMITS: TinyPNG API supports up to 500 conversions per month. A paid plan can be used after that number.
Using the [Tinify](https://github.com/tinify/tinify-python) API from TinyPNG, we can achieve huge space reductions (8MB image => 24kb after resizing from 36 megapixels > 400px for thumbnail) in order to serve images for production usage. This package provides a wrapper around the Tinify API, and uses it to automatically compress images stored in your S3 bucket. The package then overwrites those images, assuming that you only require the uncompressed versions.
## Usage
`python2 compress-s3-tinypng.py`
## Setup
1. Installation: `git clone https://github.com/rootstrap/compress-s3-tinypng`
2. Dependencies: `pip install -r requirements.txt`
- [Boto3](https://github.com/boto/boto3), [Tinify](https://github.com/tinify/tinify-python)
3. Load credentials:
- On wherever you cloned the repo, create a file named `creds.py`.
- Inside `creds.py`, copy these lines and replace the sample variables with your own access keys and parameters:
```
AWS_ACCESS_KEY_ID = 'YOUR_AWS_ID_HERE'
AWS_SECRET_ACCESS_KEY = 'YOUR_AWS_SECRET_HERE'
TINIFY_KEY = "YOUR_TINIFY_API_KEY_HERE"
AWS_BUCKET = "YOUR_BUCKET_NAME"
```
- `creds.py` is ignored by Git.
- On AWS, make sure the user you provide credentials for has full read/write access to the bucket.
- Boto3 (the AWS python SDK) will [look for credentials](http://boto3.readthedocs.io/en/latest/guide/configuration.html) on its own, but creds.py provides a layer of redundancy. If you don't have a creds.py, the script will prompt you for input and create one for you.
- The Tinify API has a free tier of 500 images a month. If you go past that, Tinify will throw an error and it will halt the program.
## License
MIT
## Credits
compress-s3-tinypng is maintained by [Rootstrap](http://www.rootstrap.com)
[
](http://www.rootstrap.com)