About
This utility was built with the static site generator Eleventy and was created by Stephanie Eckles who is both a big fan of 11ty and an advocate for modern CSS.
The primary dependency is the sharp package resize API to help calculate the focal point using Shannon entropy. Dynamically generated results are possible thanks to Eleventy Serverless.
The examples using a ratio
require browser support for aspect-ratio
(available in all evergreen browsers once Safari 15 is released).
Unfamilar with object-fit
? Check out my 2.5 minute free egghead video >
Credit for demo photo goes to Joshua Oyebanji on Unsplash.
API Options
Send a full, absolute image path as the image
URL parameter to https://objectfit-focalpoint.netlify.app/generate/
to receive the default adjustments based on an aspect-ratio of 5/3
.
Custom Ratio
To customize the ratio used, add &ratio=x/y
.
Note: if you'd like a square, pass &ratio=1/1
.
Use Image Dimensions
Optionally, pass a desired image width and height to be used instead of an aspect ratio for determining the object-position
value.
Eleventy Plugin
A plugin is available for install into your own Eleventy project to include this functionality as a Nunjucks shortcode. Get the plugin >