
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
image-focus
Advanced tools
A dependency free utility for cropping images based on a focal point ~2.13kB gzipped
A dependency free utility for cropping images based on a focus point ~2.13kB gzipped

Check out the demo and then play with editing it
Focus Coordinates range between -1 and 1 for both x and y axes. The FocusPicker class will help enable users to select the focus point to be used with an image.
There are two ways to supply the coordinates when initializing the FocusedImage class
<div class="focused-image-container">
<img class="focused-image" src="https://picsum.photos/2400/1400" data-focus-x="0.34" data-focus-y="-0.21">
</div>
import { FocusedImage } from "image-focus"
const img = document.querySelector('.focused-image') as HTMLImageElement
const focusedImage = new FocusedImage(img)
focus Option<div class="focused-image-container">
<img class="focused-image" src="https://picsum.photos/2400/1400">
</div>
import { FocusedImage } from "image-focus"
const img = document.querySelector('.focused-image') as HTMLImageElement
const focusedImage = new FocusedImage(img, {
focus: {
x: 0.34,
y: -0.21
}
})
Provide an onChange callback that will receive a Focus object that has x and y properties for the newly selected coordinates. Optionally supply a focus to initialize with, or a retina src to use instead of the default white ring SVG.
import {FocusedImage, FocusPicker} from "image-focus"
const imgEl = document.getElementById("focused-image") as HTMLImageElement
const focusedImage = new FocusedImage(imgEl)
const focusPickerEl = document.getElementById("focus-picker-img") as HTMLImageElement
const focusPicker = new FocusPicker(focusPickerEl, {
onChange: focus => focusedImage.setFocus(focus),
focus: startingFocus,
})
The <img/> element is being set to position: absolute; and having its top and left properties adjusted based on some calculations using the image and parent containers' aspect ratios and dimensions. The <img/>'s parent container gets set to position: relative; and overflow: hidden; to create the effect. There are a few other inline styles that get applied, so if anything appears to be behaving unexpectedly, be sure to check that the inline styles on both the <img/> and its parent aren't being overridden by CSS on your page (especially from rules using !important).
Additionally, because the FocusedImage is positioned absolutely so it can shift as needed, its container needs to manage its own height and width. If you aren't seeing an image appear at all, it is likely that the parent div's height is fully collapsed.
That's okay! unpkg has you covered. Just add this script tag to your page and the image-focus module is exposed in the global namespace under window.imageFocus.
<script src="https://unpkg.com/image-focus@1.0.2"></script>
Then in some script that loads after the above script tag:
var imgEl = document.querySelector('img.focused-image');
var focusedImage = new imageFocus.FocusedImage(imgEl, {x: 0.25, y: -0.3});
This project was largely inspired by and adapted from jquery-focuspoint by jonom and used typescript-library-starter to scaffold the build process.
FAQs
A dependency free utility for cropping images based on a focal point ~2.13kB gzipped
We found that image-focus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.