PHPackages                             skaught/jquery-focuspoint - 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. skaught/jquery-focuspoint

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

skaught/jquery-focuspoint
=========================

jQuery plugin for 'responsive cropping'. Dynamically crop images to fill available space without cutting out the image's subject. Great for full-screen images

v1.1.3.1(6y ago)024.8k(MIT or GPL-1.0)JavaScript

Since Dec 28Pushed 6y agoCompare

[ Source](https://github.com/skaught/jquery-focuspoint)[ Packagist](https://packagist.org/packages/skaught/jquery-focuspoint)[ Docs](http://jonom.github.io/jquery-focuspoint/)[ RSS](/packages/skaught-jquery-focuspoint/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

jQuery FocusPoint
=================

[](#jquery-focuspoint)

FocusPoint 2
------------

[](#focuspoint-2)

I started work on a major update to this plugin a couple of years ago, but it has been in limbo for a while and probably won't be picked up again unless someone wants to sponsor the work (please [get in touch](http://jonathonmenz.com) if you do!). I didn't get as far as removing the jQuery dependancy but please feel free to use the v-2-dev branch to benefit from a few new features:

- Better resizing performance
- More familiar coordinate system (like that used in CSS)
- Suppor for ideal and minimum cropping region

If you love this plugin feel free to send me an encouraging email or consider sponsoring an update. You're also welcome to make a [small donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VUDD3ACRC4TC) if you like. I receive an average of one per year, so it won't go unnoticed. 😄💰

Intelligent cropping for flexible image containers
--------------------------------------------------

[](#intelligent-cropping-for-flexible-image-containers)

[![image](demos/img/demo.jpg?raw=true)](demos/img/demo.jpg?raw=true)

Websites don't have a single layout any more. The space you have for an image may be portrait on a laptop, landscape on a tablet, and square on a mobile - particularly if you're using a full-screen image.

If you have to use the same image file in all these contexts, you might not be happy with the results you get when you 'fill' the allocated space with your image. Your subject might be clipped or completely missing, or just really awkward looking.

FocusPoint makes sure your image looks great in any container, by ensuring the 'spare' parts of your image (negative space) are cropped out before the important parts.

For a quick overview of the plugin check out this [video by Petr Tichy](http://youtu.be/Wxmxsw65BQw?t=6m49s).

Examples
--------

[](#examples)

Here are some examples showing the same image cropped a variety of different ways at once. Make sure you play with resizing the browser window to get a feel for what FocusPoint does.

- [Lizard](http://jonom.github.io/jquery-focuspoint/demos/grid/lizard.html)
- [Kangaroo](http://jonom.github.io/jquery-focuspoint/demos/grid/kangaroo.html)
- [Dolphin](http://jonom.github.io/jquery-focuspoint/demos/grid/dolphin.html)
- [Bird](http://jonom.github.io/jquery-focuspoint/demos/grid/bird.html)

And here is a [full screen](http://jonom.github.io/jquery-focuspoint/demos/full-screen/index.html) demo.

How does it work?
-----------------

[](#how-does-it-work)

The idea is that most images have a focal point or subject that is the most important part of the image. In the case of a traditional portrait photo this would be the subject's face (or specifically the spot right between their eyes). In the image above it's arguably the point halfway between the two people's faces.

FocusPoint requires you to indicate where this focal point is located within your image, and then works in the background to ensure that point is never cropped out.

How to use
----------

[](#how-to-use)

#### 1. Calculate your image's focus point

[](#1-calculate-your-images-focus-point)

An image's focus point is made up of x (horizontal) and y (vertical) coordinates. The value of a coordinate can be a number with decimal points anywhere between -1 and +1, where 0 is the centre. X:-1 indicates the left edge of the image, x:1 the right edge. For the y axis, y:1 is the top edge and y:-1 is the bottom.

[![image](demos/img/grid.png?raw=true)](demos/img/grid.png?raw=true)

**Confused?** Don't worry, there's a handy script included to help you find the focus coordinates of an image with a single click. Check out the [helper tool](http://jonom.github.io/jquery-focuspoint/demos/helper/index.html) *(vastly improved courtesy of [@auginator](https://github.com/auginator)).*

#### 2. Include javascript and CSS

[](#2-include-javascript-and-css)

You'll need to include jQuery (v1.9 or greater), the FocusPoint script, and FocusPoint css file. Example:

```

```

#### 3. Mark up your image container

[](#3-mark-up-your-image-container)

Specify the image dimensions and focus point coordinates on the image container. The image will take up whatever space is available in the container, so make sure there is some space to fill by setting a height for the container in your CSS. Example:

```

```

Note: setting `data-image-w` and `data-image-h` is optional but recommended. Omitting these value means your image will not be positioned correctly inside the frame until it has finished loading, which may cause a visible jump.

#### 4. Fire FocusPoint plugin

[](#4-fire-focuspoint-plugin)

Usually the best place for this will be inside your `$(document).ready()` function.

```
//Fire plugin
$('.focuspoint').focusPoint();
```

That's it!

#### Configuration options

[](#configuration-options)

FocusPoint comes with a few options you can change to suit your needs.

OptionValuesDefaultDescription`reCalcOnWindowResize``true` or `false``true`Whether or not to re-adjust image when the window is resized`throttleDuration`Int e.g. `0` or `100``17`Throttling rate in milliseconds. Set to `0` to disable throttling.Example usage:

```
$('.focuspoint').focusPoint({
	throttleDuration: 100 //re-focus images at most once every 100ms.
});
```

#### FocusPoint functions

[](#focuspoint-functions)

Once you have initialised FocusPoint on an image container you can access FocusPoint methods like this: `$(someContainer).data('focusPoint').methodName()`.

Or the shorter way, like this: `$(someContainer).focusPoint('methodName')`

FunctionDescription`adjustFocus()`Re-do calculations and re-position an image in it's frame. Call if container dimensions change.`windowOn()`Start window event listener and re-focus image when window is resized`windowOff()`Stop re-focusing image when window is resized#### Using FocusPoint in content sliders

[](#using-focuspoint-in-content-sliders)

Currently FocusPoint can't do it's calculations properly if an image container or it's parent is set to `display:none`, as it won't have any dimensions. This can cause problems with sliders that hide non-active slides. A work-around for now is to trigger `adjustFocus()` on the image container as soon as it become visible.

Tips &amp; Tricks
-----------------

[](#tips--tricks)

#### Image composition

[](#image-composition)

In order for this concept of 'fluid cropping' to work well, your images will need to include some negative space around the subject that you are happy to be cropped out when necessary. You don't need space on every side of the subject - but for maximum flexibility you'll want to include both some vertical and horizontal negative space.

#### Pure CSS alternative

[](#pure-css-alternative)

You can get a similar effect to this technique using only CSS and the `background-position` and `background-size` properties. Browser support isn't as good (at the moment) and your image won't be positioned exactly the same way - but it's pretty close. The CSS technique leans towards preserving the original composition while FocusPoint is biased towards keeping the subject of the image in the centre of the frame. Depending on your requirements either technique may suit you better.

- [Pure CSS example and comparison](http://jonom.github.io/jquery-focuspoint/demos/css-js-comparison/index.html)
- [Helper tool for calculating CSS values](http://jonom.github.io/jquery-focuspoint/demos/helper/index.html)

#### SilverStripe CMS integration

[](#silverstripe-cms-integration)

This plugin plays really well with the [silverstripe-focuspoint](https://github.com/jonom/silverstripe-focuspoint) module, which lets you set the focuspoint on any image with just a click, and makes the info available in your front-end templates so you don't have to do any math. It also provides really easy 'destructive' cropping outputting resampled images cropped to a particular width and height based on the same logic.

Feedback welcome!
-----------------

[](#feedback-welcome)

Nothing would encourage me to keep updating this script more than hearing how it's been used in the real world. Get in touch with me at [jonathonmenz.com](http://jonathonmenz.com) to let me know how you've used this plugin or any suggestions you have for improving it. Please [report bugs or issues on github](https://github.com/jonom/jquery-focuspoint/issues).

**Note:** To date I'm not yet aware of any live websites (apart from my own) that use this plugin - so please get in touch if you launch a site that uses FocusPoint!

#### Tip jar

[](#tip-jar)

If FocusPoint helped you impress a client and you want to say thanks, you're welcome to [leave a small donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VUDD3ACRC4TC) to help fund the purchase of coffee, which will help me stay awake during future development.

[![Donate](https://camo.githubusercontent.com/bd37932c920736cc97c5aa0740def0b4a54adbb7ec556223f6d3af90d7a1ed53/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f41552f692f62746e2f62746e5f646f6e6174655f4c472e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VUDD3ACRC4TC)

Donations received / Warm fuzzies generated: **6**
Caffé Lattes funded: **17** ☕ 😌
**Thanks!** Daniil, Cohan, Romulo, Lemuel, David

Changelog
---------

[](#changelog)

#### v1.1.1 2014-09-23

[](#v111-2014-09-23)

Minor fixes

#### v1.1.0 2014-09-18

[](#v110-2014-09-18)

Refactored code (thanks @xat)
Added ability to start/stop window-resize listener (thanks @xat)
Use % instead of px for positioning, for better scaling
Added shortcuts to plugin methods

#### v1.0.3 2014-09-06

[](#v103-2014-09-06)

Throttled window resize updates

#### v1.0.2 2014-09-05

[](#v102-2014-09-05)

Made setting image width and height on shell optional (thanks @luruke)

#### v1.0.1 2014-09-04

[](#v101-2014-09-04)

Cleaned up variables

#### v1.0.0 2014-08-19

[](#v100-2014-08-19)

Initial release

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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

Unknown

Total

1

Last Release

2333d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9575d78c26a39d45aa93b1054b54815c026872d7a257f7a461621393ac8611a2?d=identicon)[skaught](/maintainers/skaught)

---

Top Contributors

[![jonom](https://avatars.githubusercontent.com/u/1079425?v=4)](https://github.com/jonom "jonom (52 commits)")[![xat](https://avatars.githubusercontent.com/u/182512?v=4)](https://github.com/xat "xat (13 commits)")[![auginator](https://avatars.githubusercontent.com/u/1105657?v=4)](https://github.com/auginator "auginator (6 commits)")[![Chunhao137](https://avatars.githubusercontent.com/u/7862297?v=4)](https://github.com/Chunhao137 "Chunhao137 (1 commits)")[![kkirsche](https://avatars.githubusercontent.com/u/947110?v=4)](https://github.com/kkirsche "kkirsche (1 commits)")[![Lagerregal](https://avatars.githubusercontent.com/u/2297740?v=4)](https://github.com/Lagerregal "Lagerregal (1 commits)")[![LeoCreer](https://avatars.githubusercontent.com/u/6149946?v=4)](https://github.com/LeoCreer "LeoCreer (1 commits)")[![skaught](https://avatars.githubusercontent.com/u/44701?v=4)](https://github.com/skaught "skaught (1 commits)")[![wykhuh](https://avatars.githubusercontent.com/u/6968611?v=4)](https://github.com/wykhuh "wykhuh (1 commits)")[![cavemon](https://avatars.githubusercontent.com/u/12285161?v=4)](https://github.com/cavemon "cavemon (1 commits)")

### Embed Badge

![Health badge](/badges/skaught-jquery-focuspoint/health.svg)

```
[![Health](https://phpackages.com/badges/skaught-jquery-focuspoint/health.svg)](https://phpackages.com/packages/skaught-jquery-focuspoint)
```

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)[humanmade/tachyon-plugin

Rewrites WordPress image URLs to use Tachyon

87338.5k2](/packages/humanmade-tachyon-plugin)

PHPackages © 2026

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