Download the PHP package flokosiol/focus without Composer
On this page you can find all versions of the php package flokosiol/focus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package focus
Kirby Focus
With this plugin for Kirby CMS you can prevent the most important part of an image from being cropped when creating automated thumbs.
Kirby 4
[!NOTE] ✨ A core feature of Kirby 4 ✨
As of Kirby 4 this plugin has moved into core! Please find more infos on the official Kirby feature page.
There is a documented way how to migrate the existing data of your project using regex search and replace. Thanks @FynnZW!
And @bnomei created a Kirby CLI command to automate this process even further.Thanks for your amazing feedback in the last years!
Kirby 3
The plugin does two things:
- It provides a custom field that allows you to set a focus point. The focus point is saved to the meta data file.
- It provides a new method
focusCrop()
, which uses the focus point saved in the meta data file to crop an image in such a way that the focus point is in the center of the cropped image – or (if that's not possible) at least isn't cropped.
⚙️ Requirements
- Kirby CMS, Version 3.6
- GD Library or ImageMagick
Please check out the kirby-3.5
branch, if you are using Kirby 3.5 or a version even older than that.
💰 Commercial Usage
This plugin is free but if you use it in a commercial project please consider to make a donation.
🛠️ Installation
Download
Download and extract this repository, rename the folder to focus
and drop it into the plugins folder of your Kirby 3 installation. You should end up with a folder structure like this:
Composer
If you are using Composer, you can install the plugin with
Git submodule
🖼️ Usage
1. Blueprint
Add the focus field to the fields of your file blueprint (!) and set type to focus
like this:
2. Template
Use the focusCrop()
method in your template to get a complete <img>
tag:
As with every Kirby image object you can use all the known methods like this:
Some more stuff …
The plugin comes with some helper methods to get the x and y coordinates as floats or percentage values.
Focus (without cropping)
As mentioned by several people (Matthias, Guillaume and Ola) the plugin can also be used to set a custom background position without cropping the image.
Presets
If you are using the same config for focus-cropped images over and over again in your project, as of version 3.0.3 you can define them as presets in your config.php
like this:
Afterwards, you can use the presets in your templates (assuming $image
is a Kirby image object).
Focus and srcset
becomes focusSrcset()
As of Kirby 3.2 a new srcset
method was introduced. Since version 3.0.3 of the Focus plugin, you can use the following syntax in your templates to respect the focus point in your srcset options:
As of version 3.0.7 you can furthermore define your srcsets in your config.php
.
In your template file you can use the defined srcset like this:
➕ Extensions and implementations
Autofocus
Sylvain created the first Focus extension. Make sure to check it out!
This plugin acts as a JS image.upload / image.replace hook, processing the / each image with the focus component, determining its appropriate focus point and saving it to the meta data file.
https://github.com/sylvainjule/kirby-autofocus
Colorist
Kirby Colorist by @S1SYPHOS is fully compatible with Kirby Focus. This plugin is capable of image conversion to AVIF
, WebP
and some other formats, as well as resizing them.
📋 License
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.
🙌 Credits
Special thanks to all contributors!