diff --git a/wagtail/wagtailimages/models.py b/wagtail/wagtailimages/models.py
index 24fd1f0bf..921f65921 100644
--- a/wagtail/wagtailimages/models.py
+++ b/wagtail/wagtailimages/models.py
@@ -225,6 +225,12 @@ class AbstractRendition(models.Model):
def url(self):
return self.file.url
+ @property
+ def attrs(self):
+ return mark_safe(
+ 'src="%s" width="%d" height="%d" alt="%s"' % (escape(self.url), self.width, self.height, escape(self.image.title))
+ )
+
def img_tag(self):
return mark_safe(
'
' % (escape(self.url), self.width, self.height, escape(self.image.title))
diff --git a/wagtail/wagtailimages/tests.py b/wagtail/wagtailimages/tests.py
index 00d1245e6..f36751650 100644
--- a/wagtail/wagtailimages/tests.py
+++ b/wagtail/wagtailimages/tests.py
@@ -183,6 +183,18 @@ class TestImageTag(TestCase):
self.assertTrue('height="300"' in result)
self.assertTrue('alt="Test image"' in result)
+ def render_image_tag_as(self, image, filter_spec):
+ temp = template.Template('{% load image_tags %}{% image image_obj ' + filter_spec + ' as test_img %}
')
+ context = template.Context({'image_obj': image})
+ return temp.render(context)
+
+ def test_image_tag_attrs(self):
+ result = self.render_image_tag_as(self.image, 'width-400')
+
+ # Check that all the required HTML attributes are set
+ self.assertTrue('width="400"' in result)
+ self.assertTrue('height="300"' in result)
+ self.assertTrue('alt="Test image"' in result)
## ===== ADMIN VIEWS =====