Search by

studio-variable / kirby-crop

isUnknown

Crop images visually in the Kirby Panel, stored in the file and applied to every thumb

Package info

forge.studio-variable.com/studio-variable/kirby-crop.git

Homepage

Issues

Type:kirby-plugin

pkg:composer/studio-variable/kirby-crop

Statistics

Installs: 20

Dependents: 0

Suggesters: 0

v1.0.0 2026-11-18 15:09 UTC

This package is auto-updated.

Last update: 2026-11-18 16:06:31 UTC


README

Crop images visually in the Kirby Panel. The crop is stored in the file itself, so it applies everywhere the image is used: every thumb, srcset and Panel preview is generated from the cropped area, while the original stays untouched.

Installation • Usage • File methods • How it works • Configuration • Translations

Requirements

  • Kirby 5
  • PHP 8.2+
  • The GD extension (used for the crop step, whatever the thumb driver)

Installation

Composer (recommended)

composer require studio-variable/kirby-crop

Manual installation

Download this repository and copy it to site/plugins/crop.

Usage

Add a crop field to a file blueprint:

# site/blueprints/files/image.yml
fields:
  crop:
    label: Crop
    type: crop

Draw a frame on the image, move it, or resize it with the handles. The area size in pixels is shown below the image, and a button resets to the full image.

That's it: $file->thumb(), $file->resize(), $file->srcset() and presets now return cropped images.

<img src="<?= $image->thumb(['width' => 800])->url() ?>">

$file->url() still returns the uncropped original. To get an uncropped thumb, pass area: false:

$image->thumb(['width' => 800, 'area' => false]);

File methods

MethodReturnsDescription
$file->cropArea()array\|nullThe crop as fractions of the original (x, y, width, height between 0 and 1), or null if the image is not cropped
$file->cropRatio()floatWidth / height of the cropped image, or $file->ratio() if not cropped. Use it instead of ratio(), isPortrait() or isLandscape()
$file->cropPoint($x, $y)array\|nullConverts a point of the original (fractions) to the cropped image, or null if it falls outside. Useful for annotations or focus points
<figure style="aspect-ratio: <?= $image->cropRatio() ?>">
  <img src="<?= $image->thumb(['width' => 800])->url() ?>">
  <?php if ($point = $image->cropPoint(0.5, 0.3)): ?>
  <span style="left: <?= $point['x'] * 100 ?>%; top: <?= $point['y'] * 100 ?>%">Note</span>
  <?php endif ?>
</figure>

How it works

The plugin replaces the file::version and thumb components. When a file has a crop, each thumb gets a hash of the area in its filename (photo-crop1a2b3c4d-800x.webp), so changing the crop generates new thumbs. When generating, the area is cut from the original first, then handed to Kirby's own thumb component: format, quality, crop and every other option keep working.

Other plugins that read $file->root() directly, such as placeholders or color extraction, still see the full original.

Configuration

KeyTypeDefaultDescription
studio-variable.crop.fieldstring'crop'Name of the file field that stores the crop

Translations

The Panel field is translated in English and French, following the user's Panel language.

License

MIT License © 2026 Studio Variable