{"id":27767863,"url":"https://github.com/nahom-d54/django-optimize-image","last_synced_at":"2025-04-29T19:53:30.000Z","repository":{"id":284348424,"uuid":"954647983","full_name":"nahom-d54/django-optimize-image","owner":"nahom-d54","description":"A Django middleware to optimize image uploads by converting them to WebP.","archived":false,"fork":false,"pushed_at":"2025-03-25T19:53:49.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-29T19:53:26.041Z","etag":null,"topics":["django","django-framework","django-rest-framework","framework","middleware","python","web"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-optimize-image/","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/nahom-d54.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-25T12:04:04.000Z","updated_at":"2025-03-25T19:53:52.000Z","dependencies_parsed_at":"2025-03-25T13:34:45.570Z","dependency_job_id":null,"html_url":"https://github.com/nahom-d54/django-optimize-image","commit_stats":null,"previous_names":["nahom-d54/django-optimize-image","nahom-d54/django-image-optimizer"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahom-d54%2Fdjango-optimize-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahom-d54%2Fdjango-optimize-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahom-d54%2Fdjango-optimize-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahom-d54%2Fdjango-optimize-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nahom-d54","download_url":"https://codeload.github.com/nahom-d54/django-optimize-image/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251574668,"owners_count":21611386,"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-framework","django-rest-framework","framework","middleware","python","web"],"created_at":"2025-04-29T19:53:29.455Z","updated_at":"2025-04-29T19:53:29.994Z","avatar_url":"https://github.com/nahom-d54.png","language":"Python","readme":"# **Django Image Optimizer**\n\nA **Django middleware and utility** for optimizing uploaded images by converting them to WebP with configurable **width, height, and quality** settings.\n\n## **Features**\n\n✔ **Automatic optimization via middleware**  \n✔ **Manual optimization via utility function**  \n✔ **Supports per-request overrides**  \n✔ **Configurable defaults via `settings.py`**\n\n---\n\n## **Installation**\n\n```sh\npip install django-image-optimizer\n```\n\nAdd to `INSTALLED_APPS` in `settings.py`:\n\n```python\nINSTALLED_APPS = [\n    # other apps...\n    \"optimizer_middleware\",\n]\n```\n\nAdd the middleware:\n\n```python\nMIDDLEWARE = [\n    # other middleware...\n    \"optimizer_middleware.middleware.ImageOptimizationMiddleware\",\n]\n```\n\n---\n\n## **Configuration**\n\nSet global defaults in **`settings.py`**:\n\n```python\n# Default image optimization settings\nIMAGE_OPTIMIZER_WIDTH = 800   # Resize width\nIMAGE_OPTIMIZER_HEIGHT = None  # Keep aspect ratio\nIMAGE_OPTIMIZER_QUALITY = 80  # WebP quality\n```\n\n\u003e _By default, images are resized to 800px width while maintaining aspect ratio and optimized to 80% quality._\n\n---\n\n## **Usage**\n\n### **1️⃣ Automatic Optimization (Middleware)**\n\nOnce added to `MIDDLEWARE`, the optimizer **automatically processes all uploaded images** in `POST`, `PUT`, and `PATCH` requests.\n\n✅ Converts images to **WebP**  \n✅ Resizes based on `settings.py`\n\n---\n\n### **2️⃣ Dynamic Overrides (Per Request)**\n\nOverride optimization settings dynamically in a view using **`request.META`**:\n\n```python\ndef upload_view(request):\n    request.META[\"IMAGE_OPTIMIZER_WIDTH\"] = 600\n    request.META[\"IMAGE_OPTIMIZER_QUALITY\"] = 90\n    return some_response\n```\n\n---\n\n### **3️⃣ Manual Optimization (Standalone Function)**\n\nUse the function **anywhere** in your code (views, forms, serializers, etc.).\n\n```python\nfrom optimizer_middleware.utils import optimize_image\n\noptimized_image = optimize_image(image_file, width=500, quality=85)\n```\n\n---\n\n## **License**\n\n[MIT License](LICENSE). Free to use and modify. 🚀\n\n---\n\n## **Contribution**\n\nUse this guide [Contribution](https://opensource.guide/how-to-contribute/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnahom-d54%2Fdjango-optimize-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnahom-d54%2Fdjango-optimize-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnahom-d54%2Fdjango-optimize-image/lists"}