Skip to main content

django-eximagination

Fetch external images directly from templates.

A Django template tag library which allows to download external images, store them locally and return the local path to locally stored image to a desired context variable, along with width and height attributes of the image fetched. Caches the fetched images locally for the given time (set in settings).

You could, for example, use this app to solve the problems with displaying of a mixed content (assets loaded from HTTP and HTTPS sources).

Prerequisites

  • Django 1.8, 1.9, 1.10

  • Python >=2.7, >=3.4

Installation

  1. Install django-eximagination

Latest stable version on PyPI:

pip install django-eximagination

Latest stable version from GitHub:

pip install https://github.com/barseghyanartur/django-eximagination/archive/stable.tar.gz

  1. Add eximagination to INSTALLED_APPS.

INSTALLED_APPS = (
    # ...
    'eximagination',
    # ...
)
  1. Configure

By default, django-eximagination expects your files to be stored in /media/external_images directory. If location varies, redefine the directories in your Django settings, make sure the path is writable and that www-data (or whatever is applicable) has rights to write into it.

import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(BASE_DIR, '..', '..', 'media')
EXIMAGINATION_MEDIA_ROOT = os.path.join(MEDIA_ROOT, 'external_images')
EXIMAGINATION_MEDIA_URL = '/media/external_images'
EXIMAGINATION_MEDIA_RELATIVE_ROOT = 'external_images/'
# After 30 days we re-fetch the file anyway.
EXIMAGINATION_EXPIRATION_INTERVAL = 2592000

Usage example (in a Django template)

See the example directory for working code example.

Example #1:

{% load eximaginate %}

<img src="{{ MEDIA_URL }}{% eximaginate 'http://www.google.com/intl/en/images/logo.gif' %}">

Example #2:

{% load eximaginate thumbnail %}

{% eximaginate 'http://www.google.com/intl/en/images/logo.gif' as original %}

<img src="{% thumbnail original 100x100 %}">

In both cases there are two additional context variables added:

  • ei_width - Width of the image

  • ei_height - Height of the image

Testing

Simply type:

./runtests.py

or use tox:

tox

or use tox to check specific env:

tox -e py35

or run Django tests:

./manage.py test eximagination --settings=settings.testing

License

GPL 2.0/LGPL 2.1

Support

For any issues contact me at the e-mail given in the Author section or open an issue on BitBucket/GitHub.

Author

Artur Barseghyan <artur.barseghyan@gmail.com>

Release files for django-eximagination 0.8.3

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-eximagination 0.8.3
File Size Uploaded
django-eximagination-0.8.3.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-eximagination 0.8.3
File Interpreter ABI Platform
django_eximagination-0.8.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 21.4 kB

Release files / django-eximagination-0.8.3.tar.gz

Download URL django-eximagination-0.8.3.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6f913f0266be1ba9ba03470a2e3da85d45e5c12e4f9500508ce9590559072f7d
BLAKE2b-256 checksum
How to use checksums
44ee8069f2da4bf3824b1b58ad83337be797a98ae7f87d634d96fd4e82fc830c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_eximagination-0.8.3-py2.py3-none-any.whl

Download URL django_eximagination-0.8.3-py2.py3-none-any.whl
Size 13.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0f10a43549f5f239777cbbce1d1fd624206f5d91ae48a78b3cefad32e356f204
BLAKE2b-256 checksum
How to use checksums
febd0e1a44e70e50ac2389fec944687215258f6672f441a350b273d9d36e19f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.8.3 This release

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8

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