Skip to main content

django-image-optimizer pypi version

https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square https://img.shields.io/pypi/pyversions/django-image-optimizer.svg?style=flat-square https://img.shields.io/badge/Django-1.8,%201.9,%201.10,%201.11,%202.0-green.svg?style=flat-square

Django Image Optimizer is a simple Django library that allows optimization of images by using TinyPNG or Pillow.

Installation

Martor is available directly from PyPI:

  1. Installing the package.

$ pip install django-image-optimizer
  1. Don’t forget to add 'image_optimizer' to your 'INSTALLED_APPS'.

# settings.py
INSTALLED_APPS = [
    ....
    'image_optimizer',
]
  1. You have the option to use either TinyPNG or Pillow for optimizing images. Inform optimized_image which one you want to use by setting the following

# To use Pillow
OPTIMIZED_IMAGE_METHOD = 'pillow'
# To use TinyPNG
OPTIMIZED_IMAGE_METHOD = 'tinypng'

Any other string that is set for this setting will mean that optimization does not occur. If you are unsure of whether you would like to use TinyPNG or Pillow, feel free to consult the documentation of each.

If you choose to use TinyPNG, you will need to get an API key from TinyPNG. Visit https://tinypng.com/developers for more details on getting an API key. Once you have done so, add the following setting to your settings file. Note: it is a good idea to keep this secret

TINYPNG_KEY = 'your-key'
  1. You may use the OptimizedImageField by importing it

from django.db import models

from optimized_image.fields import OptimizedImageField


class MyModel(models.Model):
    ...
    image = OptimizedImageField()

and saving images into it, the same way you would to a Django ImageField. The optimized image will be saved into the url field in place of the unoptimized image.

Note about TinyPNG API keys: If you obtain the free TinyPNG API token, you are limited to 500 image optimizations per month, so this function may fail if you have a lot of images. You may either obtain a paid API key, or wait until next month.

This project also taken from: https://github.com/dchukhin/django_optimized_image

Metadata

Release files for django-image-optimizer 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-image-optimizer 1.0.0
File Size Uploaded
django-image-optimizer-1.0.0.tar.gz 4.4 kB Details

Release files / django-image-optimizer-1.0.0.tar.gz

Download URL django-image-optimizer-1.0.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3dba06be47f975768352d5b83ac8b86cf40dae25decc6572c7859824a9595fc0
BLAKE2b-256 checksum
How to use checksums
c9bdb223ef33771ec06202b9881b118e66f0fc986c03ad1f2cd06b1387665730
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page