InputfieldImage

Image upload Inputfield for FieldtypeImage fields

It renders a sortable thumbnail grid with inline descriptions, focus point controls, image editor buttons, variation management, optional client-side resizing, and all inherited InputfieldFile upload behavior.

$f = $modules->get('InputfieldImage');
$f->name = 'photos';
$f->label = 'Photos';
$f->maxFiles = 5;
$f->extensions = 'JPG JPEG GIF PNG';
$f->maxWidth = 2000;
$f->maxHeight = 2000;
$f->gridMode = 'grid'; // grid, left, or list

In normal page editing, this Inputfield is created by FieldtypeImage, which sets the page, field, value, destination path hook, and field settings. For standalone file-upload behavior, also read InputfieldFile. For shared Inputfield attributes, labels, rendering, processing, errors, and visibility selectors, see Inputfield.

Expand all      API reference

Properties

Properties marked * default from $config->adminThumbOptions and may be overridden on the Inputfield instance.

PropertyTypeDefaultDescription
extensionsstring'JPG JPEG GIF PNG'Space-separated allowed image extensions.
okExtensionsarray[]Manually whitelisted extensions, such as ['SVG'].
maxWidthint|string''Maximum uploaded image width in pixels; larger images are resized unless maxReject is enabled.
maxHeightint|string''Maximum uploaded image height in pixels; larger images are resized unless maxReject is enabled.
maxSizefloat0.0Max megapixels for client-side resize, such as 1.7; alternative to max width/height.
maxRejectbool|int0Reject images that exceed max dimensions rather than resizing them.
minWidthint|string''Minimum uploaded image width in pixels.
minHeightint|string''Minimum uploaded image height in pixels.
dimensionsByAspectRatiobool|int0Swap min/max width and height rules for portrait images.
itemClassstring'gridImage ui-widget'CSS classes used for each rendered image item. Append rather than replace unless you need full control.
useImageEditorint|bool1Whether crop, focus, variations, and action controls are available. Permission checks can disable it during render/process.
adminThumbScaleint|floatfrom configDeprecated compatibility setting; use gridSize.
resizeServerint|bool00 allows client-side resize when possible; 1 forces server-side resize.
clientQualityint90Client-side JPEG quality percentage.
editFieldNamestring''Field name to use in image editor URLs; blank uses the inputfield name.
gridSize *int130Square admin thumbnail size in pixels. Values below 100 or 260+ fall back to 130.
gridMode *string'grid'Admin display mode: grid, left, or list.
focusMode *string'on'Focus UI mode: on, zoom, or off.
imageSizerOptions *array[]Options passed to ImageSizer for admin thumbnails.

Inherited InputfieldFile properties such as maxFiles, maxFilesize, overwrite, descriptionRows, useTags, tagsList, noUpload, noAjax, and destinationPath also apply.

Constants
ConstantValueDescription
defaultGridSize130Default admin thumbnail grid size in pixels.
debugRenderValuefalseDevelopment-only flag to force render-value mode.
Rendering

render()

Render the complete image input: image grid, editor controls, upload area, and hidden data fields.

echo $f->render();

renderList($value)

Render the thumbnail grid list. $value is usually a Pageimages collection.

$html = $f->renderList($page->images);

renderItem(Pageimage $pagefile, $id, $n)

Render one image item, including thumbnail, hover controls, edit fields, action select, sort input, replace input, rename input, and focus input.

$wire->addHookAfter('InputfieldImage::renderItem', function(HookEvent $event) {
    $event->return .= '<div class="my-extra-tool"></div>';
});

renderUpload($value)

Render the image upload button/drop target. The rendered input name receives [] unless the name already ends with ].

renderButtons(Pageimage $pagefile, $id, $n)

Render the crop/focus/variations button toolbar. Returns an empty string when useImageEditor is false.

renderAdditionalFields(Pageimage $pagefile, $id, $n)

Empty hook target for adding per-image markup below the description fields.

$wire->addHookAfter('InputfieldImage::renderAdditionalFields', function(HookEvent $event) {
    $image = $event->arguments(0); /** @var Pageimage $image */
    $event->return = "<p>{$image->width} x {$image->height}</p>";
});
Thumbnails

getAdminThumb(Pageimage $img, $useSizeAttributes = true, $remove = false)

Return admin thumbnail data as an array with keys:

KeyDescription
thumbThe thumbnail Pageimage used for markup.
attrImage attribute array including src, alt, data-w, data-h, data-original, and data-focus.
markup<img> markup.
amarkupLinked <img> markup.
errorThumbnail generation error text, or blank.
titleHuman-readable title text.
$thumb = $f->getAdminThumb($pageimage, false);
echo $thumb['markup'];

buildTooltipData(Pageimage $pagefile)

Return tooltip rows as [label, value] pairs. Default rows include dimensions, filesize, variation count, and indicators for hidden status, description, and tags when present.

$wire->addHookAfter('InputfieldImage::buildTooltipData', function(HookEvent $event) {
    $data = $event->return;
    $data[] = ['EXIF', 'Available'];
    $event->return = $data;
});
Editor Actions

getImageEditButtons($pagefile, $id, $n, $buttonClass)

Return an array of crop, focus, and variations buttons. Hook after this method to add or remove editor buttons. Added in 3.0.212.

getImageThumbnailActions($pagefile, $id, $n, $class)

Return icon-only thumbnail hover actions. The default return value is an empty array; hooks may add actions. Added in 3.0.212.

getFileActions(Pageimage $pagefile)

Return actions for the image action dropdown, such as duplicate, hide/unhide, flip, rotate, grayscale, sepia, reduce 50%, and remove focus where applicable. The available actions depend on maxFiles, image extension, installed image engines, hidden status, and focus state.

$wire->addHookAfter('InputfieldImage::getFileActions', function(HookEvent $event) {
    $image = $event->arguments(0); /** @var Pageimage $image */
    $actions = $event->return;
    $actions['exif'] = 'Get EXIF data';
    $event->return = $actions;
});

processUnknownFileAction(Pageimage $pagefile, $action, $label)

Hook target for processing custom actions added through getFileActions(). Return true on success, false on failure, or null when not handled.

$wire->addHookAfter('InputfieldImage::processUnknownFileAction', function(HookEvent $event) {
    $image = $event->arguments(0); /** @var Pageimage $image */
    $action = $event->arguments(1);
    if($action === 'exif') {
        $event->message('EXIF action handled for ' . $image->name);
        $event->return = true;
    }
});
Processing

processInput(WireInputData $input)

Process uploads, deletions, descriptions, tags, sorting, focus values, and image actions. Image actions are processed only for non-AJAX saves.

processInputFile(WireInputData $input, Pageimage $pagefile, $n)

Process one image item. This extends InputfieldFile item processing with focus-point handling. Empty focus input resets to 50 50 0. Changed focus values rebuild variations.

fileAdded(Pagefile $pagefile)

Validate and post-process a newly uploaded image. Non-SVG images must have readable dimensions, are checked against min/max dimensions, and may be resized to max dimensions. SVG files bypass pixel-dimension validation and image editor operations.

Notes
  • Access via $modules->get('InputfieldImage'), or let FieldtypeImage create it automatically for image fields.
  • Client-side resize loads piexif.js and PWImageResizer.js when resize limits are configured and resizeServer=0.
  • Focus values are stored on the Pageimage as top left zoom, for example 25 75 0.
  • renderSingleItem() is deprecated and no longer used by core.
  • SVG may be allowed by adding it to extensions and okExtensions, but SVG does not use the image editor, dimension validation, or raster image actions.
  • For upload constraints, overwrite behavior, tags, descriptions, and custom Pagefile fields, see InputfieldFile.

Source files: wire/modules/Inputfield/InputfieldImage/InputfieldImage.module, wire/modules/Inputfield/InputfieldImage/config.php

API reference: methods, properties, hooks

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the InputfieldImage class also inherits all the methods and properties of: InputfieldFile, Inputfield, WireData and Wire.

Show class?     Show args?       Only hookable?    

For hooks

These methods are only useful for hooking and should not be called directly.

NameReturnSummary 
InputfieldImage::buildTooltipData($pagefile)
array

Build data for the tooltip that appears above the thumbnails

InputfieldImage::fileAdded(Pagefile $pagefile)
None

Resize images to max width/height if specified in field config and image is larger than max

InputfieldImage::getFileActions(Pageimage $pagefile)
array

Get array of actions (displayed in select dropdown) available for given Pagefile

InputfieldImage::getImageEditButtons($pagefile, string $id, int $n, string $buttonClass)
array

Get array of buttons for image edit mode

InputfieldImage::getImageThumbnailActions(Pageimage $pagefile, string $id, int $n, string $class)
array

Get the image thumbnail icon actions/links/buttons

InputfieldImage::processUnknownFileAction(Pageimage $pagefile, string $action, string $label)
bool null

Called when a select dropdown action was received that InputfieldImage does not recognize (for hooking purposes)

InputfieldImage::renderAdditionalFields($pagefile, string $id, int $n)
None

Render any additional fields (for hooks)

InputfieldImage::renderButtons($pagefile, string $id, int $n)
string

Render buttons for image edit mode

Properties

NameReturnSummary 
InputfieldImage::adminThumbScale int for backwards compatibility only
DEFAULT: auto
 
InputfieldImage::clientQuality int Quality setting to use for client-side resize. 60=60%, 90=90%, etc. .
DEFAULT: 90
 
InputfieldImage::dimensionsByAspectRatio bool int Switch min-/maxWidth and min-/maxHeight restriction for portrait images 
InputfieldImage::editFieldName string Field name to use for linking to image editor
DEFAULT: auto
 
InputfieldImage::extensions string Space separated list of allowed image extensions
DEFAULT: JPG JPEG GIF PNG
 
InputfieldImage::focusMode string May be 'on', 'off', or 'zoom'
DEFAULT: on
 
InputfieldImage::gridMode string Default grid mode in admin, one of "grid", "left" or "list"
DEFAULT: grid
 
InputfieldImage::gridSize int Squared size of the admin thumbnails
DEFAULT: 130
 
InputfieldImage::imageSizerOptions array Options to pass along to the ImageSizer class. See /wire/config.php $imageSizerOptions for details. 
InputfieldImage::itemClass string Space separated CSS classes for items rendered by this Inputfield. Generally you should append rather than replace. 
InputfieldImage::maxHeight int string Max height for uploaded images, larger will be sized down
DEFAULT: ''
 
InputfieldImage::maxReject bool int Reject images that exceed max allowed size?
DEFAULT: false
 
InputfieldImage::maxSize float Maximum number of megapixels for client-side resize, i.e. 1.7 is ~1600x1000, alt. to maxWidth/maxHeight .
DEFAULT: 0
 
InputfieldImage::maxWidth int string Max width for uploaded images, larger will be sized down
DEFAULT: ''
 
InputfieldImage::minHeight int string Min height for uploaded images, smaller will be refused
DEFAULT: ''
 
InputfieldImage::minWidth int string Min width for uploaded images, smaller will be refused
DEFAULT: ''
 
InputfieldImage::okExtensions array Array of manually whitelisted extensions, for instance [ 'SVG' ] must be manually whitelisted if allowed.
DEFAULT: []
 
InputfieldImage::resizeServer int bool Resize to max width/height at server? 1=Server-only, 0=Use client-side resize when possible .
DEFAULT: 0
 
InputfieldImage::useImageEditor int bool Whether or not the modal image editor is allowed for this field
DEFAULT: true
 

Additional methods and properties

In addition to the methods and properties above, InputfieldImage also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.269