Process Images

A Textformatter that processes <img> tags within rich text content.

A basic, proof-of-concept Textformatter module for ProcessWire. When the Textformatter is applied to a rich text field it uses Simple HTML DOM to find <img> tags in the field value and passes each img node through a hookable TextformatterProcessImages::processImg() method.

This is a very simple module that doesn't have any configurable settings and doesn't do anything to the field value unless you hook the TextformatterProcessImages::processImg() method.

Hook example


When added to /site/ready.php the hook below will replace any Pageimages in a rich text field with a 250px square variation and wrap the <img> tag in a link to the original full-size image.

For help with Simple HTML DOM refer to its documentation.

$wire->addHookAfter('TextformatterProcessImages::processImg', function(HookEvent $event) {

    // The Simple HTML DOM node for the <img> tag
    /** @var \simple_html_dom_node $img */
    $img = $event->arguments(0);
    // The Pageimage in the <img> src, if any (will be null for external images)
    /** @var Pageimage $pageimage */
    $pageimage = $event->arguments(1);
    // The Page object in case you need it
    /** @var Page $page */
    $page = $event->arguments(2);
    // The Field object in case you need it
    /** @var Field $field */
    $field = $event->arguments(3);

    // Only for images that have a src corresponding to a PW Pageimage
    if($pageimage) {
        // Set the src to a 250x250 variation
        $img->src = $pageimage->size(250,250)->url;
        // Wrap the img in a lightbox link to the original
        $img->outertext = "<a href='{$pageimage->url}'>{$img->outertext}</a>";
    }

});

More modules by Robin S

  • Hanna Code Dialog

    Enhances the use of Hanna tags in CKEditor fields, including the dialog-based editing of Hanna tags.
  • Connect Page Fields

    Allows the connecting of two related Page fields so that changing one updates the other.
  • Minimal Fieldset

    Adds a config option to fieldsets to render them without label or padding in Page Edit.
  • Template Field Widths

    Quickly set the widths of inputfields in a template.
  • Custom Inputfield Dependencies

    Extends inputfield dependencies so that inputfield visibility or required status may be determined at runtime by selector or custom PHP code.
  • Breadcrumb Dropdowns

    Adds dropdown menus of page edit links to the breadcrumbs in Page Edit.
  • Auto Template Stubs

    Automatically creates stub files for templates when fields or fieldgroups are saved.
  • Custom Admin Menus

    Adds up to three custom dropdowns to the main admin menu.
  • Page List Select Multiple Quickly

    Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing.

All modules by Robin S

Install and use modules at your own risk. Always have a site and database backup before installing new modules.