Skip to main content

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 %}

Metadata

Release files for django-subject-imagefield 0.2.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-subject-imagefield 0.2.13
File Size Uploaded
django-subject-imagefield-0.2.13.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-subject-imagefield 0.2.13
File Interpreter ABI Platform
django_subject_imagefield-0.2.13-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / django-subject-imagefield-0.2.13.tar.gz

Download URL django-subject-imagefield-0.2.13.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3c674dbbaca5fd932cfbad295594b141b073907b774d084153da9235af49e0be
BLAKE2b-256 checksum
How to use checksums
b7876c5211596945709f5dd43ff5ea9f05a5233c5f15625b392480e846f22df7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / django_subject_imagefield-0.2.13-py3-none-any.whl

Download URL django_subject_imagefield-0.2.13-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05a2472defd3f764d940e532768c8b34c3d0fff6a276b2670108b11650e6f858
BLAKE2b-256 checksum
How to use checksums
0350cb194c098a5b4185d74f8090e6377013287c64fb124c70d3299ea32b10b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.2.13 This release

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page