Skip to main content

django-exiffield extracts exif information by utilizing the exiftool.

Project description

django-exiffield

PyPI GitHub Workflow Status (master) Coveralls github branch PyPI - Python Version PyPI - License

django-exiffield extracts exif information by utilizing the exiftool.

Requirements

  • Python 3.6.1 or newer
  • exiftool
  • Django >= 2.2

Installation

  1. Install django-exiffield

    pip install django-exiffield
    
  2. Make sure exiftool is executable from you environment.

Integration

Let's assume we have an image Model with a single ImageField. To extract exif information for an attached image, add an ExifField, specify the name of the ImageField in the source argument

from django.db import models

from exiffield.fields import ExifField


class Image(models.Model):
    image = models.ImageField()
    exif = ExifField(
        source='image',
    )

and create a migration for the new field. That's it.

After attaching an image to your ImageField, the exif information is stored as a dict on the ExifField. Each exif information of the dictionary consists of two keys:

  • desc: A human readable description
  • val: The value for the entry.

In the following example we access the camera model

image = Image.objects.get(...)
print(image.exif['Model'])
# {
#     'desc': 'Camera Model Name',
#     'val': 'DMC-GX7',
# }

As the exif information is encoded in a simple dict you can iterate and access the values with all familiar dictionary methods.

Denormalizing Fields

Since the ExifField stores its data simply as text, it is not possible to filter or access indiviual values efficiently. The ExifField provides a convinient way to denormalize certain values using the denormalized_fields argument. It takes a dictionary with the target field as key and a simple getter function of type Callable[[Dict[Dict[str, str]]], Any]. To denormalize a simple value you can use the provided exiffield.getters.exifgetter

from django.db import models

from exiffield.fields import ExifField
from exiffield.getters import exifgetter


class Image(models.Model):
    image = models.ImageField()
    camera = models.CharField(
        editable=False,
        max_length=100,
    )
    exif = ExifField(
        source='image',
        denormalized_fields={
            'camera': exifgetter('Model'),
        },
    )

There are more predefined getters in exiffield.getters:

exifgetter(exif_key: str) -> str
Get an unmodified exif value.

get_type() -> str
Get file type, e.g. video or image

get_datetaken -> Optional[datetime]
Get when the file was created as datetime

get_orientation -> exiffield.getters.Orientation
Get orientation of media file. Possible values are LANDSCAPE and PORTRAIT.

get_sequenctype -> exiffield.getters.Mode
Guess if the image was taken in a sequence. Possible values are BURST, BRACKETING, TIMELAPSE and SINGLE.

get_sequencenumber -> int
Get image position in a sequence.

Development

This project uses poetry for packaging and managing all dependencies and pre-commit to run flake8, isort, mypy and black.

Clone this repository and run

poetry install
poetry run pre-commit install

to create a virtual enviroment containing all dependencies. Afterwards, You can run the test suite using

poetry run pytest

This repository follows the Conventional Commits style.

Cookiecutter template

This project was created using cruft and the cookiecutter-pyproject template. In order to update this repository to the latest template version run

cruft update

in the root of this repository.

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-exiffield-3.0.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

django_exiffield-3.0.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file django-exiffield-3.0.0.tar.gz.

File metadata

  • Download URL: django-exiffield-3.0.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for django-exiffield-3.0.0.tar.gz
Algorithm Hash digest
SHA256 969c1c081e5a12004332e0f31da969914edcf543a54ee5588546a0296b02e9bb
MD5 0ea2ec1f80d48667ea5e09cd985e1bf1
BLAKE2b-256 156f777cada4f064598efa4f596321b2f5519170fff69c1a765388f8ea8bc489

See more details on using hashes here.

File details

Details for the file django_exiffield-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_exiffield-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for django_exiffield-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 781da79d2dbc94670dfe848bbd232e9840b8cf74a8af1a3d025be00cfcb52cb6
MD5 cce9f9cd35de4691b18e6e1152760450
BLAKE2b-256 92e7dfdf24cb1b1a7e9277ca98293fe0020c222c55cb90ea97cadcc96697ca02

See more details on using hashes here.

Supported by

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