Personal tools
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

Using PIL

Using the Python Imaging Library to scale images on-the-fly

Martin Aspeli

This tutorial will teach you how to create content types the Plone 2.1 way, using the ATContentTypes library, by following the example of RichDocument, an extension of Plone's standard Page/Document type.
Page 13 of 17.

The Python Imaging Library, PIL, is capable of (among other things) re-scaling images on-the-fly. The Archetypes ImageField can take a sizes attribute to define the possible sizes an image can be scaled to. ATContentTypes defines the following sizes in 'ATContentTypes/content/image.py':

   sizes= {'large'   : (768, 768),
           'preview' : (400, 400),
           'mini'    : (200, 200),
           'thumb'   : (128, 128),
           'tile'    :  (64, 64),
           'icon'    :  (32, 32),
           'listing' :  (16, 16),
          }

These can then be referred to by name. For example, to render the thumbnails in the richdocument_view_preview template, we do:

  <img tal:replace="structure python:image.tag(scale='thumb')"/>

where image is an ImageAttachment object.

 
by Martin Aspeli last modified September 5, 2005 - 10:59 All content is copyright Plone Foundation and the individual contributors.

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by