studio-variable / kirby-crop
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
Type:kirby-plugin
pkg:composer/studio-variable/kirby-crop
Requires
- php: >=8.2
- getkirby/composer-installer: ^1.2
Requires (Dev)
- getkirby/cms: ^5.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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
| Method | Returns | Description |
|---|---|---|
$file->cropArea() | array\|null | The crop as fractions of the original (x, y, width, height between 0 and 1), or null if the image is not cropped |
$file->cropRatio() | float | Width / height of the cropped image, or $file->ratio() if not cropped. Use it instead of ratio(), isPortrait() or isLandscape() |
$file->cropPoint($x, $y) | array\|null | Converts 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
| Key | Type | Default | Description |
|---|---|---|---|
studio-variable.crop.field | string | '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