Scaling

This module contains functions to scale images in particular ways. The functions operate on raw image data and have no Zope dependencies.

Functions

plone.scale.scale.scaleImage(image, width=None, height=None, direction='down', quality=88, result=None)

Scale an image to another size.

The generated image is a JPEG image, unless the original is a PNG image. This is needed to make sure alpha channel information is not lost, which JPEG does not support.

Scaling can happen in two directions: up scaling scales the smallest dimension up to the required size, while down scaling starts by scaling the largest dimension to the required size. This differences can be very important. For logos use up scaling, while normal photo usage in CMS contexts usually requires down scaling.

Alternatively, it’s possible to use PIL’s thumbnail algorithm to keep the present aspect ratio of the image. To do so “keep” must be passed as the value of the direction parameter.

The image parameter can either be the raw image data (ie a str instance) or an open file.

The quality parameter can be used to set the quality of the resulting image scales.

The return value is a tuple with the new image, the image format and a size-tuple. Optionally a file-like object can be given as the result parameter, in which the generated image scale will be stored.

Table Of Contents

Previous topic

plone.scale – Image scaling logic

Next topic

Storage

This Page