Cut off the head in nginx

    Not so long ago, I talked about how Topface stores and distributes custom images on Topface Developer Day ( presentation on speakerdeck ). We cut pictures on the fly in nginx using image_filter.

    People are mostly oblong in the vertical direction and photographs of themselves for the dating service make appropriate ones, designers want small squares, and nginx cuts out to people not quite what people are interested in (I mean the face). Using the example of longcat, we get something like the following:

    longcat

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

    Customization

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

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

    Good examples


    Vertical pictures

    Original:

    Original vertical image

    Alignment to the top: image_filter_offset center top;

    Aligned to top vertical image

    Alignment to the center (normal behavior): image_filter_offset center center;

    Aligned to center vertical image

    Alignment to the bottom:image_filter_offset center bottom;

    Aligned to bottom vertical image

    Horizontal pictures

    Original:

    Original horizontal image

    Left justify: image_filter_offset left center;

    Aligned to left horizontal image

    Center justify (normal behavior): image_filter_offset center center;

    Aligned to center horizontal image

    Right justify: image_filter_offset right center;

    Aligned to right horizontal image

    For those who missed: link to github .

    Also popular now: