How to resize a Dexterity image widget?
Asked Answered
I

2

5

I'm using a DisplayForm for my view class and succeeded rendering a NamedBlobImage field with:

<span tal:replace="structure view/w/image/render" />

How can I tweak that ZPT to display a different image size like 'image_mini' or any other from plone.app.imaging ?

Ipswich answered 8/9, 2011 at 11:10 Comment(0)
B
5

You should use plone.app.imaging for this.

It would be like:

<img tal:define="scales context/@@images;
                 thumbnail python: scales.scale('image', width=64, height=64);"
     tal:condition="thumbnail"
     tal:attributes="src thumbnail/url;
                     width thumbnail/width;
                     height thumbnail/height" />

Where context is the object which holds the image and image (on scales.scale('image'...) is the field name that has the image you want to resize.

If you want to use the predefined image sizes just use:

<img tal:define="scale context/@@images"
     tal:replace="structure python: scale.scale('image',
                  scale='mini').tag()" />

Cheers

Burrill answered 8/9, 2011 at 13:14 Comment(0)
R
7

Just as with Archetypes image fields, a set of predefined scales are automatically available in Dexterity. The convenience shortcut to get at these is to use code like:

<img src=”#” tal:replace=”structure
 context/@@images/fieldname/scale” />

where "fieldname" is the name of the field and "scale" is one of the pre-defined scales.

Take a look at http://pypi.python.org/pypi/plone.namedfile/#image-scales for full information.

Rusticus answered 8/9, 2011 at 15:23 Comment(0)
B
5

You should use plone.app.imaging for this.

It would be like:

<img tal:define="scales context/@@images;
                 thumbnail python: scales.scale('image', width=64, height=64);"
     tal:condition="thumbnail"
     tal:attributes="src thumbnail/url;
                     width thumbnail/width;
                     height thumbnail/height" />

Where context is the object which holds the image and image (on scales.scale('image'...) is the field name that has the image you want to resize.

If you want to use the predefined image sizes just use:

<img tal:define="scale context/@@images"
     tal:replace="structure python: scale.scale('image',
                  scale='mini').tag()" />

Cheers

Burrill answered 8/9, 2011 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.