Installation & Setup
Installation
Install the module with Composer and enable it:
composer require drupal/ai_image_crop
drush en ai_image_crop
The module depends on the Drupal AI module (ai). If it is not already
installed, Composer will pull it in automatically.
Module configuration
Navigate to Administration > Configuration > AI > AI Image Crop
(/admin/config/ai/ai-image-crop).
AI Model
Select the vision-capable chat model that will analyze your images. The list
only contains configured models that can receive images as part of a chat
message. Choose Default to use the Chat with Image Vision default model
from the AI module's settings (/admin/config/ai/settings).
Tested configurations:
| Provider | Model |
|---|---|
| OpenAI | gpt-5.1 |
| OpenAI | gpt-4o |
Maximum iterations
Controls how many rounds the AI gets to refine its crop suggestion. Each round, the module draws the current proposals on the image and asks the AI to pick the best or suggest improvements.
- 1 -- fastest; the AI proposes crops and picks one immediately.
- 2-3 -- good balance between speed and quality.
- 5+ -- more refinement, but more API calls and slower.
The default is 2.
Grid settings (focal point only)
For focal point detection the module uses a grid-based zoom approach. The grid columns and rows control how many cells the image is divided into on each zoom pass. A 5x5 grid (the default) gives 25 cells per round.
Default prompts
Two default prompts guide the AI:
- Focal point prompt -- tells the AI what to focus on when placing a focal point (faces, eyes, products, text, etc.).
- Crop prompt -- tells the AI how to compose a crop (rule of thirds, breathing room, avoid cutting subjects, etc.).
Both can be overridden per widget instance on the form display settings.
Bulk action behavior
When running the bulk action, you can control how images that already have crops are handled:
- Follow widget settings -- respects each widget's "Override existing" checkbox.
- Always replace -- re-crops everything.
- Skip existing -- only processes images that have no crop yet.
- Replace default focal points only -- Focal Point saves a crop at its configured default position (normally the center) whenever an image is saved, so on an existing library almost every image already has one and "Skip existing" would skip them all. This option replaces focal points that still sit exactly at that default, keeps the ones an editor moved, and skips every existing Image Widget Crop crop.
The bulk action writes crop entities directly and invalidates the entity's render cache. It does not re-save the entity, so no new revision is created, the changed time is left alone, and other modules' presave hooks do not run.
Views Bulk Operations
With Views Bulk Operations installed, add the Views bulk operations field to a view of nodes or media and enable the AI Image Crop action. Large selections are then processed in batches. Entities the user may not update are skipped.
The same action can run from Drush on any view:
drush vbo-execute content ai_image_crop:crop_action:node
Drush
The module's own Drush command does not need a view:
# Specific entities.
drush ai-image-crop:apply node 1,2,3
# Every entity of a bundle, or of the type when --bundle is left out.
drush ai-image-crop:apply media --bundle=image
Entities are loaded in chunks of 50 to keep memory use low. The command follows the bulk action behavior above and bypasses access checks, as Drush is trusted. Each image is a separate AI request, so processing a whole library can take long and cost accordingly.
Widget setup
Focal Point widget
- Go to Administration > Structure > Content types > [Your type] > Manage form display.
- On the image field, select the Focal Point widget (or keep it if already selected).
- Click the gear icon to open widget settings.
- Check Enable AI crop suggestions.
- Optionally enter a custom prompt. Leave blank to use the global default.
- Save.
Field Widget Actions
If the Field Widget Actions module (1.5 or later) is installed, this module provides two actions:
- AI Focal Point for the Focal Point widget.
- AI Crop for the Image Widget Crop widget, which suggests a crop area for every crop type configured on the widget.
To add one:
- On Manage form display, open the widget settings (gear icon).
- In Field Widget Actions, choose the action and click Add action.
- Enable it and save. Optionally set a button label, a custom AI prompt, and whether existing crops may be overridden.
The button appears next to each uploaded image and applies the AI suggestion the same way the built-in button does. The actions are only offered while a vision-capable model is available; if none is configured, they are hidden from both the settings form and the content form.
Automatic mode
Each action has an Automatically option. When enabled, the suggestion is requested as soon as the form loads, without the editor pressing anything, so uploaded images get a focal point or crop without any interaction.
Cost
Automatic mode sends one request per image every time the form is built. On forms with many images, or on busy editorial workflows, this multiplies AI provider usage. Prefer it on fields where images are uploaded rarely.
Setup with a recipe
Field Widget Actions provides a config action so the button can be added by a recipe instead of by hand:
config:
actions:
core.entity_form_display.node.article.default:
setComponentThirdPartySetting:
component: field_image
provider: field_widget_actions
settings:
ai_focal_point:
plugin_id: ai_image_crop_focal_point
enabled: true
automatic: false
weight: 0
button_label: 'Suggest AI Focal Point'
settings:
prompt: ''
override_existing: false
AI Automators
If the AI Automators submodule of the AI module is installed, two automators can set crops when an entity is saved, with no button press at all. AI Automators requires the Token module.
- AI Image Crop: Focal Point places a focal point for the Focal Point module.
- AI Image Crop: Crop Areas fills the crop types you select, for the Image Widget Crop widget.
To add one:
- On Manage fields, edit the image field.
- Enable AI Automator and choose the automator.
- Pick the image field itself as the base field. For crop areas, select which crop types to fill. Optionally add guidance, and save.
Images that already have a focal point, or a crop for a selected crop type, are skipped, so manual adjustments are never overwritten and no request is spent on work that is already done.
Cost
Automators run on every entity save. The focal point automator sends one request per image without a focal point; the crop area automator sends one per image and per selected crop type that has no crop yet. Selecting several crop types multiplies the cost of creating content.
Both automators only appear while the crop module is installed and a vision-capable model is available.
Automator or button?
They solve different problems, and the ordering of Drupal's hooks is the reason:
- Automators run on
hook_entity_presave, while Focal Point and Image Widget Crop write their own crops fromhook_entity_insertandhook_entity_update, which run afterwards. The focal point automator therefore also writes the chosen position onto the field item, so Focal Point stores that instead of its configured default. Focal Point works in whole percentages, so it can round the position by up to one percent of the image. - Automators are the better fit for content created without a form: migrations, feeds, programmatic saves and media library uploads.
- The Field Widget Action buttons are the better fit while editing a form, because the editor sees the result immediately and can adjust it before saving.
Using both at once is supported: whichever runs first fills the crop, and the other one then sees it as already set and does nothing.
Permissions
The suggestion buttons read the uploaded file, so the editor needs view access
to it. For files in the public file system that means the View published
content (access content) permission, which authenticated editors normally
have.
Image Widget Crop widget
- Go to Administration > Structure > Content types > [Your type] > Manage form display.
- On the image field, select the ImageWidget crop widget.
- Click the gear icon to open widget settings.
- Check Enable AI crop suggestions.
- Optionally enter a custom prompt.
- Save.
Verifying it works
- Edit or create a node with an image field that has AI crop enabled.
- Upload an image.
- Click the Suggest AI Crop button.
- The focal point marker or crop rectangle should move to the AI-suggested position within a few seconds.