Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize a Dexterity image widget?

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 ?

like image 712
Davi Lima Avatar asked Sep 08 '11 11:09

Davi Lima


2 Answers

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.

like image 177
SteveM Avatar answered Sep 30 '22 12:09

SteveM


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

like image 42
gforcada Avatar answered Sep 30 '22 12:09

gforcada