All Projects → flokosiol → Kirby Focus

flokosiol / Kirby Focus

Licence: mit
Better image cropping for Kirby CMS

Projects that are alternatives of or similar to Kirby Focus

Kirby Imageset
A flexible, responsive image component for Kirby 2, featuring lazy-loading, fancy placeholders and much more.
Stars: ✭ 122 (-28.24%)
Mutual labels:  kirby, kirby-plugin
Kirby Autogit
⬢ Saves every change made via Kirby Panel to a Git repository
Stars: ✭ 147 (-13.53%)
Mutual labels:  kirby, kirby-plugin
Cartkit
Cartkit - The [quick] starter kit!
Stars: ✭ 39 (-77.06%)
Mutual labels:  kirby, kirby-plugin
Kirby Calendar Plugin
A plugin for the Kirby CMS to easily implement an event calendar.
Stars: ✭ 76 (-55.29%)
Mutual labels:  kirby, kirby-plugin
Kirby Imagekit
Asynchronous thumbnail creation and optimization for Kirby 2
Stars: ✭ 109 (-35.88%)
Mutual labels:  kirby, kirby-plugin
kirby-architect
📐 Easily reference Blueprint data from anywhere in your Kirby application.
Stars: ✭ 38 (-77.65%)
Mutual labels:  kirby, kirby-plugin
Panel Bar
panelBar for Kirby 2 CMS
Stars: ✭ 70 (-58.82%)
Mutual labels:  kirby, kirby-plugin
kirby-file-types
Show file fields only for specific file types
Stars: ✭ 13 (-92.35%)
Mutual labels:  kirby, kirby-plugin
Field Multiselect
Multiselect field for Kirby 2 CMS
Stars: ✭ 84 (-50.59%)
Mutual labels:  kirby, kirby-plugin
kirby-copy-files
Clone page dashboard widget for Kirby panel
Stars: ✭ 12 (-92.94%)
Mutual labels:  kirby, kirby-plugin
retour-for-kirby
Kirby 3 plugin to manage redirects and track 404s right from the Panel
Stars: ✭ 96 (-43.53%)
Mutual labels:  kirby, kirby-plugin
Kirby Typography
Typographic enhancements for your Kirby-driven website.
Stars: ✭ 80 (-52.94%)
Mutual labels:  kirby, kirby-plugin
queue-for-kirby
Basic queue for Kirby 2, using Cron and Kirby's flat file system
Stars: ✭ 17 (-90%)
Mutual labels:  kirby, kirby-plugin
Embed
Media embed plugin for Kirby 2 CMS
Stars: ✭ 73 (-57.06%)
Mutual labels:  kirby, kirby-plugin
kirbyup
🆙 Zero-config bundler for Kirby Panel plugins
Stars: ✭ 33 (-80.59%)
Mutual labels:  kirby, kirby-plugin
kirby-blade
Enable Laravel Blade Template Engine for Kirby 3
Stars: ✭ 20 (-88.24%)
Mutual labels:  kirby, kirby-plugin
kirby-boiler-field
Boilerplate for Kirby form fields
Stars: ✭ 15 (-91.18%)
Mutual labels:  kirby, kirby-plugin
kirby3-many-to-many-field
This plugin allows you to create many-to-many relationships between pages in Kirby and synchronizes them on both sides.
Stars: ✭ 38 (-77.65%)
Mutual labels:  kirby, kirby-plugin
search-for-kirby
Kirby 3 plugin for adding a search index (sqlite or Algolia).
Stars: ✭ 42 (-75.29%)
Mutual labels:  kirby, kirby-plugin
Kirby Sri
Subresource integrity hashing & cache-busting static assets for Kirby
Stars: ✭ 9 (-94.71%)
Mutual labels:  kirby, kirby-plugin

Kirby Focus

Version License Kirby

With this plugin for Kirby CMS you can prevent the most important part of an image from being cropped when creating automated thumbs.

The plugin does two things:

  1. It provides a custom field that allows you to set a focus point. The focus point is saved to the meta data file.
  2. 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.x
  • GD Library or ImageMagick

Commercial Usage

This plugin is free but if you use it in a commercial project please consider to.

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:

site/plugins/focus/

Composer

If you are using Composer, you can install the plugin with

composer require flokosiol/focus

Git submodule

git submodule add https://github.com/flokosiol/kirby-focus.git site/plugins/focus

Usage

1. Blueprint

Add the focus field to the fields of your file blueprint (!) and set type to focus like this:

fields:
  focus:
    label: My Focus Field
    type: focus
    width: 1/2

2. Template

Use the focusCrop() method in your template to get a complete <img> tag:

<?php
  // you need a Kirby image object like this
  $image = $page->images()->first();

  // crop a square of 200px x 200px
  echo $image->focusCrop(200);

  // crop a rectangle of 300px x 200px
  echo $image->focusCrop(300, 200);

  // crop a rectangle of 200px x 400px with a quality of 80%
  echo $image->focusCrop(200, 400, ['quality' => 80]);

  // crop a grayscale square of 300px x 300px
  echo $image->focusCrop(300, 300, ['grayscale' => true]);

  // crop a rectangle of 200px x 300px and force coordinates (overrides user input)
  echo $image->focusCrop(200, 300, ['focusX' => 0.3, 'focusY' => 0.6]);
?>

As with every Kirby image object you can use all the known methods like this:

<?php
  $url = $image->focusCrop(200, 300)->url();
  $filename = $image->focusCrop(150)->filename();
?>

Some more stuff …

The plugin comes with some helper methods to get the x and y coordinates as floats or percentage values.

<?php
  $x = $image->focusX();
  $y = $image->focusY();

  $x = $image->focusPercentageX();
  $y = $image->focusPercentageY();
?>

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.

<div style="background-image: url(<?php echo $image->url() ?>); background-size: cover; background-position: <?php echo $image->focusPercentageX() ?>% <?php echo $image->focusPercentageY() ?>%;"></div>

<img src="<?php echo $image->url() ?>" style="object-fit: cover; object-position: <?php echo $image->focusPercentageX() ?>% <?php echo $image->focusPercentageY() ?>%;" />

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:

<img 
  src="<?= $image->focusCrop(1000, 1000)->url() ?>"
  srcset="<?=
    $image->focusSrcset([
      '800w' => [
          'width' => 800,
          'height' => 800,
      ],
      '1400w' => [
          'width' => 1400,
          'height' => 1400,
      ]
    ]);
  ?>"
>

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:

return [
  'flokosiol' => [
    'focus' => [
      'presets' => [
        'square' => [
          'width'=> 500
        ],
        'rectangle' => [
          'width'=> 500,
          'height'=> 300,
          'options' => [
            'grayscale' => true
          ]
        ]
      ]
    ]
  ]
];

Afterwards, you can use the presets in your templates (assuming $image is a Kirby image object).

<?= $image->focusPreset('square') ?>
<?= $image->focusPreset('rectangle') ?>

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

MIT

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!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].