This code is already running on my own project, though to share.
I changed some functions names here on the fly, might missed something

 * Implments hook_filter_info()
 * Add new filter to display images in colorbox
function colorbox_filter_info() {
  $filters['filter_colorbox'] = array(
    'title' => t('Image Colorbox'),
    'process callback' => '_filter_colorbox',
    'tips callback' => '_filter_colorbox_tips',

  return $filters;

 * The actual filter code. wrap images with [a] tag with proper colorbox class
function _filter_colorbox($text, $filter, $format, $langcode, $cache, $cache_id) {
  $dom = filter_dom_load($text);
  $images = $dom->getElementsByTagName('img');

  // iterate images
  foreach ($images as $img) {
    // make sure img is wrapped withing a link, keeping in mind
    // that we don't need nested a tags, so we check fist if one exists;
    $parentNode = $img->parentNode;
    if ($parentNode->nodeName != 'a') {
      // create the new link
      $aNode = $dom->createElement('a');
      $aNode->setAttribute('href', $img->getAttribute('src'));

      //Replace image with this wrapper a
      $parentNode->replaceChild($aNode, $img);

      //Append this image to wrapper a

    // note that we didn't override the href of the parent a tag if already exist, we don't want to ruin
    // the users links

  return $dom->saveHTML();

 * colorbox filter tips
function _filter_colorbox_tips($filter, $format, $long)
  if ($long) {
    return t('Surrounds image tags with proper html and prepare it for colorbox jquery library modal view');
  else {
    return ('show images in colorbox modal');


amagdy’s picture

Assigned: amagdy » Unassigned

Not sure why this issue was assigned to me, I've no privileges to commit to this project (would be happy to help though).

Can one of the maintainer add my code ?

frjo’s picture

Status: Needs review » Needs work

Make it a patch and make sure it follows Drupal coding standard and I will test it out.