PHPackages                             freshleafmedia/autofocus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. freshleafmedia/autofocus

ActiveLibrary[Image &amp; Media](/categories/media)

freshleafmedia/autofocus
========================

Automatic image focal point detection

1.0.2(2y ago)812.7k↓45.7%1[1 issues](https://github.com/freshleafmedia/autofocus/issues)1MITPHPPHP ^8.0

Since Oct 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/freshleafmedia/autofocus)[ Packagist](https://packagist.org/packages/freshleafmedia/autofocus)[ RSS](/packages/freshleafmedia-autofocus/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (1)

Autofocus
=========

[](#autofocus)

Automatic image focal point detection.

Overview
--------

[](#overview)

Autofocus is an image analysis library which attempts to determine where the focal point of an image is.

Installation
------------

[](#installation)

```
composer require freshleafmedia/autofocus

```

Usage
-----

[](#usage)

```
use FreshleafMedia\Autofocus\FocalPointDetector;

$focalPointDetector = new FocalPointDetector();

$point = $focalPointDetector->getPoint(new Imagick('/path/to/image'));

$point->x; // 283
$point->y; // 157
```

How it works
------------

[](#how-it-works)

The algorithm works by picking the busiest area of the image:

1. Detect edges
2. Apply a vignette. This pushes the focus towards the centre
3. Split the image into segments
4. Calculate the average brightness within each segment
5. Pick the segment with the highest brightness

 [![](assets/owl.jpg)](assets/owl.jpg) [![](assets/owl-edges.jpg)](assets/owl-edges.jpg) [![](assets/owl-vignette.jpg)](assets/owl-vignette.jpg) [![](assets/owl-segment.jpg)](assets/owl-segment.jpg) [![](assets/owl-average.jpg)](assets/owl-average.jpg) [![](assets/owl-select.jpg)](assets/owl-select.jpg)

Options
-------

[](#options)

The `FocalPointDetector` constructor takes a number of options:

```
new FocalPointDetector(
    segmentSize: 20, // The size of the Segments in pixels
);
```

Debugging
---------

[](#debugging)

You can get access to the processed image to see how the focus was determined:

```
use FreshleafMedia\Autofocus\FocalPointDetector;

$focalPointDetector = new FocalPointDetector();

$focalPointDetector
    ->debug(new Imagick('/path/to/image'))
    ->drawHeatMap()
    ->drawGrid()
    ->getRawImage()
    ->writeImage(__DIR__ . '/debug.jpg');
```

Tests
-----

[](#tests)

Unit tests can be run via `composer test`

Credits
-------

[](#credits)

This library is essentially a PHP port of .

License
-------

[](#license)

See [LICENSE](LICENSE)

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~206 days

Total

3

Last Release

947d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10062339?v=4)[Freshleaf Media](/maintainers/freshleafmedia)[@freshleafmedia](https://github.com/freshleafmedia)

---

Top Contributors

[![freshleafmedia](https://avatars.githubusercontent.com/u/10062339?v=4)](https://github.com/freshleafmedia "freshleafmedia (11 commits)")

---

Tags

autofocuscropfocal-pointhacktoberfestimagephp

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/freshleafmedia-autofocus/health.svg)

```
[![Health](https://phpackages.com/badges/freshleafmedia-autofocus/health.svg)](https://phpackages.com/packages/freshleafmedia-autofocus)
```

###  Alternatives

[goat1000/svggraph

Generates SVG graphs

135911.1k3](/packages/goat1000-svggraph)[gravatarphp/gravatar

Gravatar URL builder which is most commonly called as a Gravatar library

16653.6k2](/packages/gravatarphp-gravatar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
