📜 ⬆️ ⬇️

We cut off the head in nginx

Not so long ago, I told you how the storage and distribution of user images on Topface Developer Day ( presentation on speakerdeck ) is arranged in our Topface . Pictures we cut on the fly in nginx using image_filter.

People are mostly elongated in the vertical direction and photos of themselves for the dating service make appropriate, the designers want little squares, and nginx cuts out people not exactly what people are interested in (I mean the face). Using the example of longcat, you get something like the following:

longcat

You have to live with it in the usual way: take it and add it yourself. As a result, I got a patch for the image_filter module, which can tell which side of the image you do not need to cut off the edges when crop occurs. All good on github .
')
Customization

It's simple, you need to enter a directive in the location or server you need.

image_filter_offset {left,center,right} {top,center,bottom};

Illustrative examples


Vertical pictures

Original:

Original vertical image

Align top: image_filter_offset center top;

Aligned to top vertical image

Center alignment (normal behavior): image_filter_offset center center;

Aligned to center vertical image

Align bottom: image_filter_offset center bottom;

Aligned to bottom vertical image

Horizontal pictures

Original:

Original horizontal image

Align left: image_filter_offset left center;

Aligned to left horizontal image

Center alignment (normal behavior): image_filter_offset center center;

Aligned to center horizontal image

Right alignment: image_filter_offset right center;

Aligned to right horizontal image

For those who missed: a link to github .

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


All Articles