Skip to main content

A model ImageField with subject position support

Project description

django-subject-imagefield

This package provides a SubjectImageField model field which inherits from the core ImageField and adds support for subject position. The position coordiantes are stored inside another model field defined as an option (as it occurs with the width and height optional ImageField parameters). A custom form field and widgets are used in order to allow the user to easily set the image subject dragging a pin over an image preview. Some convenience properties are added to the attr_class of the field in order to access the subject position coordinates in a template.

Use it together with some sort of thumbs generator application in order to show always the relevan part of an image, I find it playing well with sorl-thumbnail.

screencast

Tested for django >= 1.11

Installation

Install with pip

$ pip install django-subject-imagefield

Add it to your installed apps:

INSTALLED_APPS = {
    #...
    subject_imagefield,
}

Configuration

You can set the image preview width for the widget:

SUBJECT_IMAGEFIELD = {
    'PREVIEW_WIDTH': 500
}

Value is considered as number of pixels, default: 300.

Usage

In you models:

from subject_imagefield.fields import SubjectImageField

class MyModel(models.Model):
    image = SubjectImageField('image', upload_to='pages/img', subject_location_field='subject_location')
    subject_location = models.CharField('subject coords', max_length=7)

In a django template you've access to the following properties:

  • subject_perc_position: a dictionary containing the subject position in percentage coordinates, i.e: {'x': 15, 'y': 37}
  • subject_position: a dictionary containing the subject position coordinates in px relative to the original image dimensions, i.e: {'x': 700, 'y': 345}
  • sorl: a shortcut to get a string used as cropping paramenter for sorl-thumbnail templatetag, i.e: '15% 37%'

Example:

{% load sorl_thumbnail %}

<p>Perc. subject position: {{ object.image.subject_perc_position }}</p>
<p>Original dimensions subject position: {{ object.image.subject_position }}</p>
<p>Thumb cropped considering subject position:</p>
{% thumbnail object.image "200x800" crop=object.image.sorl as thumb %}
<img src="{{ thumb.url }}" alt="ftw" />
{% endthumbnail %}

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-subject-imagefield-0.2.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_subject_imagefield-0.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file django-subject-imagefield-0.2.0.tar.gz.

File metadata

  • Download URL: django-subject-imagefield-0.2.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.8

File hashes

Hashes for django-subject-imagefield-0.2.0.tar.gz
Algorithm Hash digest
SHA256 88ad2f487c470ad57eb8ad77e6c361723ca281c88724514cf5a527bc6922edbe
MD5 583bccf6cfd0ce0557f6dc8fe0ffdb67
BLAKE2b-256 594eb9df71fa894704dc28f531d7c8b7accaf4f5f3a52d92d8e254d83b7189b8

See more details on using hashes here.

File details

Details for the file django_subject_imagefield-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_subject_imagefield-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.8

File hashes

Hashes for django_subject_imagefield-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83b6b362ff5e20ba2e4c0f1a0e581f8838785fad08afe3fe76eda9b901e7cbbc
MD5 c37e4e10f66d4360e7b3e61fa1d07f1d
BLAKE2b-256 baa9b6587ec3cc495a8be4c7faf64bcc9b9b312ee17ca5bd12a433465c0a4436

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