https://github.com/mbrav/heifmgur
Experimental Image upload service API in Django using the HEIF image format
https://github.com/mbrav/heifmgur
api conversion django django-rest-framework heic heif python rest-api
Last synced: 2 months ago
JSON representation
Experimental Image upload service API in Django using the HEIF image format
- Host: GitHub
- URL: https://github.com/mbrav/heifmgur
- Owner: mbrav
- License: gpl-3.0
- Created: 2021-12-29T19:36:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-09T16:25:26.000Z (over 4 years ago)
- Last Synced: 2025-03-20T17:54:30.941Z (over 1 year ago)
- Topics: api, conversion, django, django-rest-framework, heic, heif, python, rest-api
- Language: Python
- Homepage:
- Size: 151 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/mbrav/heifmgur/actions/workflows/django.yml)
[](https://wakatime.com/badge/user/54ad05ce-f39b-4fa3-9f2a-6fe4b1c53ba4/project/f52550ff-f468-4b17-834d-fecce184459a)
Image upload service API in Django using High Efficiency Image File Format (HEIF)
## Motivation
This project is a continuation of a job interview assignment. The intention was to create an image service REST API out of it, but not just any API, but one that uses more efficient image formats such as HEIF. Unfortunately however, HEIF format is not well supported in open source projects due to its [proprietary licensing](https://github.com/nokiatech/heif/blob/master/LICENSE.TXT) by Nokia. This includes in image libraries like Django and Pillow, which Django relies on for image validation:
- [ Support for HEIF #2806 ](https://github.com/python-pillow/Pillow/issues/2806)
While there are existing python libraries that can decode HEIF files, there are none that **encode** into HEIF. Fortunately, there is an exception by using the Python [Wand library](https://pypi.org/project/Wand/) which is a wrapper for ImageMagick command tool. Although it must be system installed in order for the Python library to work, it does contain contain a HEIF decoder. This is why the project uses Wand and [Pillow-SIMD](https://python-pillow.org/pillow-perf/) to [bounce back files](api/utils/img.py) between them. Although Wand is faster than Pillow, it is slower than the x86 performance-optimized Pillow-SIMD.
Due to lack of HEIF support in Pillow, Django's ImageField does not support the format since it uses Pillow for image validation. As a result, a custom field based on Django's FileField had to be written with image validation using the Wand library, which leverages ImageMgick's usage of [libheif](https://github.com/strukturag/libheif) library.
Although writing this project was interesting, I rather wish Nokia Corporation to go bankrupt unless it open sources the HEIC format and allow it to flourish.
## Instructions
Before proceeding make sure [ImageMagick](https://imagemagick.org/script/download.php) is installed on your system and command `magick identify -list format` includes HEIC and HEIF fomrats.
```
$ git clone https://github.com/mbrav/heifmgur.git
$ cd heifmgur
```
Setup a local python environment:
```
$ python3 -m venv venv
$ source venv/bin/activate
```
Install dependencies with poetry:
```
$ poetry install
```
Setup Django database and migrations:
```
$ python3 manage.py makemigrations
$ python3 manage.py migrate
```
Setup an admin user (not required):
```
$ python3 manage.py createsuperuser
```
Run server
```
$ python3 manage.py runserver
```
Go to [http://127.0.0.1:8000/](http://127.0.0.1:8000/)