Providing a specific width on the scale?

We have a customer requirement that for a certain image scale (teaser scale) the width should always be 160px regardless of the image ratio . Specifying how (160,160) the scale does not work for images where the height is greater than the width. In this case, 160px will be used.

Any idea how to provide a fixed value of 160 pixels in each case?

+4
source share
2 answers

In Plone 4, there is a completely new way to generate scales that can help solve this problem. Using this approach, you can say that it scales the image β€œdown” instead of β€œup”, which means that it scales the short side of the image to the specified size, not the long side (so that the image ends with cropping, but always fills the specified area) .

With this approach, you do not need to determine the scale in your circuit, but you can simply include something like the following in the template. 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 on this scaling approach.

+3
source

I used these scales on the site and worked fine:

 image_scales = {'thumb': (150,600), 'mini': (200, 800)} 

The idea is to have a very long height, so regardless of the ratio of the image to the picture, it will always be 150 or 200 pixels wide.

+4
source

Source: https://habr.com/ru/post/1345703/


All Articles