{"id":16550584,"url":"https://github.com/agusmakmun/django-image-optimizer","last_synced_at":"2025-03-21T10:32:03.388Z","repository":{"id":54309219,"uuid":"142098749","full_name":"agusmakmun/django-image-optimizer","owner":"agusmakmun","description":"Django library that allows optimization of images by using TinyPNG or Pillow","archived":false,"fork":false,"pushed_at":"2022-10-18T01:03:34.000Z","size":38,"stargazers_count":24,"open_issues_count":2,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-24T22:23:54.217Z","etag":null,"topics":["django","django-image-compressor","django-image-optimizer","image-compressor","image-optimization","pillow","tinypng"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/agusmakmun.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-24T03:20:54.000Z","updated_at":"2023-03-11T22:37:52.000Z","dependencies_parsed_at":"2022-08-13T11:40:23.126Z","dependency_job_id":null,"html_url":"https://github.com/agusmakmun/django-image-optimizer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agusmakmun%2Fdjango-image-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agusmakmun%2Fdjango-image-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agusmakmun%2Fdjango-image-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agusmakmun%2Fdjango-image-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agusmakmun","download_url":"https://codeload.github.com/agusmakmun/django-image-optimizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244135405,"owners_count":20403796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-image-compressor","django-image-optimizer","image-compressor","image-optimization","pillow","tinypng"],"created_at":"2024-10-11T19:34:54.577Z","updated_at":"2025-03-21T10:32:03.095Z","avatar_url":"https://github.com/agusmakmun.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"django-image-optimizer |pypi version|\n---------------------------------------\n\n.. |pypi version|\n   image:: https://img.shields.io/pypi/v/django-image-optimizer.svg\n   :target: https://pypi.python.org/pypi/django-image-optimizer\n\n.. image:: https://img.shields.io/badge/license-MIT-blue.svg\n   :target: https://raw.githubusercontent.com/agusmakmun/django-image-optimizer/master/LICENSE\n\n.. image:: https://img.shields.io/pypi/pyversions/django-image-optimizer.svg\n   :target: https://pypi.python.org/pypi/django-image-optimizer\n\n.. image:: https://img.shields.io/badge/Django-1.8%20%3E=%203.0-green.svg\n  :target: https://www.djangoproject.com\n\n\nDjango Image Optimizer is a simple Django library that allows optimization\nof images by using `TinyPNG \u003chttps://tinypng.com/\u003e`_ or `Pillow \u003cpillow.readthedocs.io/\u003e`_.\n\n\nInstallation\n------------------------------\n\nDjango Image Optimizer is available directly from `PyPI \u003chttps://pypi.python.org/pypi/django-image-optimizer\u003e`_:\n\n1. Installing the package.\n\n::\n\n    $ pip install django-image-optimizer\n\n\n2. Don't forget to add ``'image_optimizer'`` to your ``'INSTALLED_APPS'``.\n\n::\n\n    # settings.py\n    INSTALLED_APPS = [\n        ....\n        'image_optimizer',\n    ]\n\n\n3. You have the option to use either TinyPNG or Pillow for optimizing images.\n   Inform ``optimized_image`` which one you want to use by setting the following\n\n::\n\n    # To use Pillow\n    OPTIMIZED_IMAGE_METHOD = 'pillow'\n    # To use TinyPNG\n    OPTIMIZED_IMAGE_METHOD = 'tinypng'\n\nAny other string that is set for this setting will mean that optimization does\nnot occur. If you are unsure of whether you would like to use TinyPNG or Pillow,\nfeel free to consult the documentation of each.\n\nIf you choose to use TinyPNG, you will need to get an API key from\nTinyPNG. Visit https://tinypng.com/developers for more details on getting an\nAPI key. Once you have done so, add the following setting to your settings\nfile. Note: it is a good idea to keep this secret\n\n::\n\n    TINYPNG_KEY = 'your-key'\n\n\n4. You may use the ``OptimizedImageField`` by importing it\n\n::\n\n    from django.db import models\n\n    from image_optimizer.fields import OptimizedImageField\n\n\n    class MyModel(models.Model):\n        ...\n        image = OptimizedImageField()\n\n\n    class MyModel2(models.Model):\n        \"\"\"\n        If you using OPTIMIZED_IMAGE_METHOD = 'pillow'\n        You can use this optional arguments.\n\n        This model represents a MyModel2 with a few\n        fields including a `image` field which is an OptimizedImageField\n        instance with `optimized_image_output_size` and\n        `optimized_image_resize_method` arguments set.\n\n        This means that image would be a resized\n        version of the source image, meant to keep a given screen resolution,\n        in this case (400, 300) pixels.\n        \"\"\"\n        image = OptimizedImageField(\n            upload_to=\"uploads/%Y/%m/%d\",\n            optimized_image_output_size=(400, 300),\n            optimized_image_resize_method=\"cover\"  #  \"crop\", \"cover\", \"contain\", \"width\", \"height\", \"thumbnail\" or None\n        )\n\n\nand saving images into it, the same way you would to a Django ``ImageField``.\nThe optimized image will be saved into the ``url`` field in place of the\nunoptimized image.\n\n\n5. Or you can directly use the ``image_optimizer`` function from utils.\n\n::\n\n    from image_optimizer.utils import image_optimizer\n\n\n    def post_image(request):\n        image_data = request.FILES.get('image')\n        image_data = image_optimizer(image_data=image_data,\n                                     output_size=(400, 300),\n                                     resize_method='cover')\n        ....\n\n\n**P.S:**\n\n Note about TinyPNG API keys: If you obtain the free TinyPNG API token, you are limited to 500\n image optimizations per month, so this function may fail if you have a\n lot of images. You may either obtain a paid API key, or wait until next month.\n\nThis project forked from: https://github.com/dchukhin/django_optimized_image\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagusmakmun%2Fdjango-image-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagusmakmun%2Fdjango-image-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagusmakmun%2Fdjango-image-optimizer/lists"}