Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Picture plugin: Add support for width and height #1520

wants to merge 3 commits into from

3 participants


Model updated with supporting fields to hold width/height, template now uses same.


migrations are missing.


and maybe add the widht and hight in a default hidden advanced tab in the form.


Are we sure we need these fields? Natural width and height are available on the ImageField instance, and if the image needs to be scaled, it's probably a better idea to use something like easy_thumbnails and the width value provided from the placeholder.


I close this pull request as i think @piquadrat is right on this one.

@digi604 digi604 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 16, 2012
  1. @mkoistinen

    Update cms/plugins/picture/

    mkoistinen authored
    Added width/height fields to data model
  2. @mkoistinen

    Update cms/plugins/picture/templates/cms/plugins/picture.html

    mkoistinen authored
    Using width and height tags
Commits on Nov 17, 2012
  1. @mkoistinen

    Update cms/plugins/picture/templates/cms/plugins/picture.html

    mkoistinen authored
    Fixed width/height attributes
This page is out of date. Refresh to see the latest.
6 cms/plugins/picture/
@@ -1,4 +1,3 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
@@ -17,7 +16,10 @@ class Picture(CMSPlugin):
(CENTER, _("center")),
- image = models.ImageField(_("image"), upload_to=CMSPlugin.get_media_path)
+ image_width = models.PositiveIntegerField("Image_width", blank=True, null=True)
+ image_height = models.PositiveIntegerField("Image_height", blank=True, null=True)
+ image = models.ImageField(_("image"), width_field="image_width",
+ height_field="image_height", upload_to=CMSPlugin.get_media_path)
url = models.CharField(_("link"), max_length=255, blank=True, null=True,
help_text=_("If present, clicking on image will take user to link."))
page_link = models.ForeignKey(Page, verbose_name=_("page"), null=True,
2  cms/plugins/picture/templates/cms/plugins/picture.html
@@ -1,5 +1,5 @@
<span class="plugin_picture{% if picture.float %} align-{{ picture.float }}{% endif %}">
{% if link %}<a href="{{ link }}">{% endif %}
-<img src="{{ picture.image.url }}" alt="{{ picture.alt }}"{% if picture.longdesc %} title="{{ picture.longdesc }}"{% endif %} />
+<img src="{{ picture.image.url }}" width="{{ picture.image.width }}" height="{{ picture.image.height }}" alt="{{ picture.alt }}"{% if picture.longdesc %} title="{{ picture.longdesc }}"{% endif %} />
{% if link %}</a>{% endif %}
Something went wrong with that request. Please try again.