This project is not covered by Drupal’s security advisory policy.
Image Crop Library lets editors crop images for real: it writes the cropped pixels to a new file instead of just applying a crop on top of the original. The original file, its Media entity and any existing Crop entities are never changed.
Each crop is saved with a name and kept in a reusable library tied to the original image. Editors can pick a saved crop for another placement without recropping and without affecting other places that use the same image.
Features
- Physical, non-destructive cropping: produces a new File (or a new Media entity of the same bundle for Media fields). Source bytes stay untouched.
- Named, reusable crops: save several crops of one original (freeform or using aspect presets) and reuse them from a thumbnail library.
- Always crops from the original: reused and re-edited crops are cut again from the full-resolution source, never from an already-cropped copy.
- Save-bound staging: "Apply" creates a private, temporary preview. The crop is only finalized when the parent form or layout is saved, so cancelled or abandoned edits never appear in the library.
- Access-aware: File, Media and private-download permissions, and publishing status, are checked when crops are listed, previewed, selected and saved. Private sources produce private crops.
- Works in the editor's usual places: image and Media fields, Media Library, CKEditor 5 images and Media embeds, and (optionally) IMCE.
- Leaves your configuration alone: adds its own table, routes, permission and form adapters. Existing image styles, text formats, field storage and content are not modified.
How it works with image Media
The original Media entity is never modified. Each crop creates a new Media entity of the same bundle pointing to a new, physically cropped File. Only the placement being edited is switched to the copy.
Where the crop button appears
- Media reference fields (Media Library widget) on nodes, paragraphs and inline blocks: the crop applies only to that field, delta and language.
- embeds in CKEditor 5: only the selected embed's
data-entity-uuidis replaced. The rest of the HTML is left as is. - Editing an existing image Media item: you get a separate copy. The Media being edited is not changed.
Lifecycle
- Open: the module checks that the editor can view the source Media and can create Media of that bundle. If the source is an earlier copy, the editor reopens the full-resolution original rather than the cropped pixels.
- Apply: the cropped image is written to a private temporary File, and an unpublished draft Media is created as a duplicate of the source, with its image field and thumbnail pointing to the new File. Scheduled publish/unpublish dates are cleared, and any content moderation workflow starts at its default state.
- Save the parent form: the source and placement are checked again; if anything changed, the save is refused. The File is copied to its final public or private location, and the copy takes the same published status as the source, per translation, so an unpublished source never yields a published copy. The crop is then added to the named crop library for that original.
- Cancel or abandon: the draft stays private and unpublished, never appears in the library, and is removed by cron.
Example
Media 12 "Factory photo" (published) ← never changed └─ cropped in node 5 / field_hero / delta 0 → Media 87 "Factory photo — edited copy" image field → File 340 (cropped pixels) published on node save, same as Media 12 node 5 field_hero: 12 → 87
Reusing a saved crop elsewhere creates another independent copy, re-cropped from Media 12's original. Media 87 is not shared.
Things to know
- The Media Library gains one "— edited copy" item per cropped placement.
- Editors need create permission for each Media bundle they crop.
- If a bundle already uses a Crop API crop type through its image style, map it in
source_crop_types. The existing crop then becomes the starting selection, and copies get a full-frame crop so they are not cropped twice.
Requirements
- Drupal 11, PHP 8.3+
- Core: File, Image, Media, Media Library, Views
- Crop API
Optional integrations
- IMCE: guarded upload, delete and resize operations so files used by crops can't be removed or overwritten.
- CKEditor 5: crop images and Media embeds directly from the editor.
Installation
composer require drupal/image_crop_library drush en image_crop_library
Grant the edit image placements permission to editor roles. The crop button then appears on supported image and Media widgets.
Similar projects
- Image Widget Crop and Focal Point store crop coordinates and apply them through image styles. Image Crop Library creates real cropped files instead, keeps a library of named crops per original, and never alters the shared source asset.
Limitations
- No automatic desktop/mobile art direction.
- Does not migrate or bulk-convert existing crops or content.
Project information
- Project categories: Content editing experience, Media
- Created by livido on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
