django-subject-imagefield


Namedjango-subject-imagefield JSON
Version 0.2.13 PyPI version JSON
download
home_pagehttp://github.com/otto-torino/django-subject-imagefield
SummaryA model ImageField with subject position support
upload_time2023-12-07 12:47:43
maintainer
docs_urlNone
authorabidibo
requires_python
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/jazzband/sorl-thumbnail).

![screencast](screencast.gif)

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

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/otto-torino/django-subject-imagefield",
    "name": "django-subject-imagefield",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "abidibo",
    "author_email": "abidibo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b7/87/6c5211596945709f5dd43ff5ea9f05a5233c5f15625b392480e846f22df7/django-subject-imagefield-0.2.13.tar.gz",
    "platform": null,
    "description": "# django-subject-imagefield\n\nThis package provides a `SubjectImageField` model field which inherits from the core `ImageField` and adds support for subject position.\nThe position coordiantes are stored inside another model field defined as an option (as it occurs with the width and height optional ImageField parameters).\nA 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.\nSome convenience properties are added to the `attr_class` of the field in order to access the subject position coordinates in a template.\n\nUse 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](https://github.com/jazzband/sorl-thumbnail).\n\n![screencast](screencast.gif)\n\nTested for django >= 1.11\n\n## Installation\n\nInstall with pip\n\n    $ pip install django-subject-imagefield\n\nAdd it to your installed apps:\n\n    INSTALLED_APPS = {\n        #...\n        subject_imagefield,\n    }\n\n## Configuration\n\nYou can set the image preview width for the widget:\n\n    SUBJECT_IMAGEFIELD = {\n        'PREVIEW_WIDTH': 500\n    }\n\nValue is considered as number of pixels, default: 300.\n\n## Usage\n\nIn you models:\n\n    from subject_imagefield.fields import SubjectImageField\n\n    class MyModel(models.Model):\n        image = SubjectImageField('image', upload_to='pages/img', subject_location_field='subject_location')\n        subject_location = models.CharField('subject coords', max_length=7)\n\nIn a django template you've access to the following properties:\n\n- __subject_perc_position__: a dictionary containing the subject position in percentage coordinates, i.e: `{'x': 15, 'y': 37}`\n- __subject_position__: a dictionary containing the subject position coordinates in px relative to the original image dimensions, i.e: `{'x': 700, 'y': 345}`\n- __sorl__: a shortcut to get a string used as cropping paramenter for sorl-thumbnail templatetag, i.e: `'15% 37%'`\n\nExample:\n\n    {% load sorl_thumbnail %}\n\n    <p>Perc. subject position: {{ object.image.subject_perc_position }}</p>\n    <p>Original dimensions subject position: {{ object.image.subject_position }}</p>\n    <p>Thumb cropped considering subject position:</p>\n    {% thumbnail object.image \"200x800\" crop=object.image.sorl as thumb %}\n    <img src=\"{{ thumb.url }}\" alt=\"ftw\" />\n    {% endthumbnail %}\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A model ImageField with subject position support",
    "version": "0.2.13",
    "project_urls": {
        "Homepage": "http://github.com/otto-torino/django-subject-imagefield"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0350cb194c098a5b4185d74f8090e6377013287c64fb124c70d3299ea32b10b7",
                "md5": "8533251fc3268cab8b8399c54c5bec50",
                "sha256": "05a2472defd3f764d940e532768c8b34c3d0fff6a276b2670108b11650e6f858"
            },
            "downloads": -1,
            "filename": "django_subject_imagefield-0.2.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8533251fc3268cab8b8399c54c5bec50",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9221,
            "upload_time": "2023-12-07T12:47:42",
            "upload_time_iso_8601": "2023-12-07T12:47:42.074078Z",
            "url": "https://files.pythonhosted.org/packages/03/50/cb194c098a5b4185d74f8090e6377013287c64fb124c70d3299ea32b10b7/django_subject_imagefield-0.2.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7876c5211596945709f5dd43ff5ea9f05a5233c5f15625b392480e846f22df7",
                "md5": "21ca90fe1a9dbb8c4217417abcb470d3",
                "sha256": "3c674dbbaca5fd932cfbad295594b141b073907b774d084153da9235af49e0be"
            },
            "downloads": -1,
            "filename": "django-subject-imagefield-0.2.13.tar.gz",
            "has_sig": false,
            "md5_digest": "21ca90fe1a9dbb8c4217417abcb470d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7325,
            "upload_time": "2023-12-07T12:47:43",
            "upload_time_iso_8601": "2023-12-07T12:47:43.848392Z",
            "url": "https://files.pythonhosted.org/packages/b7/87/6c5211596945709f5dd43ff5ea9f05a5233c5f15625b392480e846f22df7/django-subject-imagefield-0.2.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-07 12:47:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "otto-torino",
    "github_project": "django-subject-imagefield",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-subject-imagefield"
}
        
Elapsed time: 0.64748s