ckanext-datasetthumbnail
This CKAN extension adds support for generation and display of thumbnail images for datasets.
The helper function thumbnail_url can be called from a template, as in this example:
{% block thumbnail %}
{% set thumbnail = h.thumbnail_url(package.id) %}
{% if thumbnail %}
<a href="{{ h.url_for(controller='package', action='read', id=package.name) }}">
<img class="dataset-list-thumbnail" src="{{ thumbnail }}">
</a>
{% endif %}
{% endblock %}
Thumbnail Selection Logic
- If a resource exists with the name
thumbnail.png, this will be used.
- If no resource exists with this name and the logged-in user has sufficient access, the thumbnail will be generated from the first matching JPEG or PNG resource.
- If no thumbnail exists at this point, a placeholder image will be used.
Requirements
- CKAN 2.5.2
- Pillow 3.2.0 (with PngImagePlugin and JpegImagePlugin)
Installation
To install ckanext-datasetthumbnail:
- Activate your CKAN virtual environment:
. /usr/lib/ckan/default/bin/activate
- Install the ckanext-datasetthumbnail Python package:
pip install ckanext-datasetthumbnail
Add datasetthumbnail to the ckan.plugins setting in your CKAN config file.
Restart CKAN.
Config Settings
# Show thumbnails (optional, default: False)
ckan.datasetthumbnail.show_thumbnail = True
# Autogenerate thumbnails (optional, default: False)
ckan.datasetthumbnail.auto_generate = True
# Generated thumbnail width (optional, default: 140)
ckan.datasetthumbnail.thumbnail_width = 140
# Generated thumbnail height (optional, default: int(width * 1.415))
ckan.datasetthumbnail.thumbnail_height = 140
About
Copyright (c) 2016 MapAction. Developed by Aptivate.
Development of v1 of this plugin was funded by ECHO (European Commission Humanitarian Aid).
License
This extension is licensed under the AGPL-3.0 license.