This question has been answered by hochmohr. See the first response.
<?php function simpleStr($matches) { return $matches[0]; } function encodeImg($matches) { $img = $matches[0]; $cnt=preg_match_all('#src="[^"]*"#', $img, $srcarr); if ($cnt>0) { $src = substr($srcarr[0][0],5,-1); $thumb = "<a href=\"$src\" title=\"a bigger image\" rel=\"lightbox-1\"><img src=\"[[phpthumbof? &input=`$src` &options=`&w=120&h=120&zc=1&fltr[]=gray`]]\" /></a>"; return $thumb; } else { return $img; } } $gallery = $modx->getService('gallery','Gallery',$modx->getOption('gallery.core_path',null,$modx->getOption('core_path').'components/gallery/').'model/gallery/',$scriptProperties); if (!($gallery instanceof Gallery)) return ''; $output = $modx->resource->content; $output = preg_replace_callback('#<img class="thumb" src="[^"]*" .*/>#', 'encodeImg', $output); $modx->resource->content= $output; return;