coxmi / image-focal-point

WordPress focal point selection for images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image focal point

WordPress plugin to select a focal point for images in your media library


Screenshot

Installation

Upload the plugin folder to the plugins directory, and activate on the plugins page.

Usage

In your theme, get the focal point position by calling get_post_meta with your attachment’s $id:

<?php
  $x = get_post_meta($attachmentId, "x", true);
  $y = get_post_meta($attachmentId, "y", true);
?>

The values returned are percentages from the left and top edges of the image, so you can use them in object-position or background-position:

<?php
  $focalpoint = "${x}% ${y}%";
  …
?>

<img style="object-position:<?php echo $focalpoint ?>">

About

WordPress focal point selection for images


Languages

Language:JavaScript 62.1%Language:PHP 21.9%Language:CSS 16.0%