Skip to main content

Image compressor for Django apps.

Project description

Django Image Compressor

Django Image Compressor is a tool to compress your images. Easy to plug-in and easy to use. The tool compresses the uploaded image before saving data to db.

Installation

To install django-image-compressor

$ pip install django-image-compressor

Add the app to your project:

# settings.py
INSTALLED_APPS = (
    ...
    'django-image-compressor',
    ...
)

Usage

Package will add additional 4 fields to your forms. You can compress your images by reducing the quality of the images or resize them or both. If you leave input width and/or height fields empty and try to resize your image, sizes will be reduced twice. Only compressed images will be saved to your db and original ones will be ignored.

In order to use the compressor, first create a ModelForm in forms.py and add ImageCompressorFormMixin to your form:

# forms.py
from django import forms
from django_image_compressor.mixins import ImageCompressorFormMixin

class YourImageUploadForm(ImageCompressorFormMixin, forms.ModelForm):
    ...
    compressed_image_fields = ('your_image_field_1', 'your_image_field2', ...)
    ...

If you want to add compressor to your Django Admin Site, then add ImageCompressorAdminMixin and the created form to your ModelAdmin class.

# admin.py
from django.contrib import admin
from django_image_compressor.mixins import ImageCompressorAdminMixin
from .forms.py import YourImageUploadForm

class YourModelAdmin(ImageCompressorAdminMixin, admin.ModelAdmin):
    ...
    custom_form = YourImageUploadForm
    ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-image-compressor-0.3.6.tar.gz (8.7 kB view details)

Uploaded Source

File details

Details for the file django-image-compressor-0.3.6.tar.gz.

File metadata

  • Download URL: django-image-compressor-0.3.6.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for django-image-compressor-0.3.6.tar.gz
Algorithm Hash digest
SHA256 6d319148bd67ba6c36155fb0401356f5073f6f69c0d39814e9d4a84f430e9fd0
MD5 f06396a1c995d287d31a54d5d4755680
BLAKE2b-256 48a0a76678725696a739d8dd864b448bc4bf5a5073f41cea3a3da87aeb74d07c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page