Enforcing a particular width on a scale?
We have the cust开发者_JAVA百科omer requirement that for a particular scale of an image ('teaser' scale) the width has to the always 160px independent of the image ratio. Specifying as (160,160) scale does not work for images where the height is larger than the width. In this case 160px will be used.
Any idea how to ensure a fixed with of 160px in every case?
I used this scales in a site and it worked OK:
image_scales = {'thumb': (150,600), 'mini': (200, 800)}
The idea is to have a very long height so no matter the image ratio of the picture, it will always be 150 or 200 px width.
In Plone 4 there is an entirely new way of generating scales which can help with this problem. Using this approach you can tell it to scale the image 'down' instead of 'up', which means that it will scale the short side of the image to the specified size, rather than the long side (so the image ends up getting cropped, but always fills the specified area).
With this approach, you don't have to define the scales in your schema, but can simply include something like the following in your template. The scale will be generated on demand.
<img tal:define="scale context/@@images"
tal:replace="structure python: scale.scale('image',
width=160, height=160, direction='down').tag()" />
See the plone.app.imaging page for more examples of this approach to scaling.
精彩评论