Question

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 ?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top