Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


Prevent images wider than a certain number of pixels from getting automatically inlined, ruining the usability of the site.


Add the following code into your local configuration file and change the value of $ImageMaxWidth to taste:

 $ImageMaxWidth = 600;

 function MyFmtUrlLink($pat,$ref,$txt) {
   global  $InterMapUrls, $ImgExtPattern, $UrlLinkFmt, $UrlImgFmt, $UrlLinkTextFmt, $ImageMaxWidth;
   $link = $UrlLinkFmt; $rtxt=$ref;

   if (!is_null($txt)) { $rtxt=$txt; $link=$UrlLinkTextFmt; }
   elseif (preg_match("/$ImgExtPattern\$/",$ref)) 
   if (preg_match('/^([^:]*):/',$ref,$match)) {
     if (@$InterMapUrls[$match[1]]) 
   if ($isimage) 
     list($width, $height, $type, $attr) = getimagesize($ref);
     if ($width < $ImageMaxWidth) $link=$UrlImgFmt; 
   $link = str_replace('$Url',$ref,$link);
   return str_replace('$LinkText',$rtxt,$link);

 $FmtUrlLink = 'MyFmtUrlLink';

See Also

For a more full-featured approach, have a look at PictureGallery.

Comments & Bugs

This code performs an additional access to the disk subsystem (through the getimage() function) for every displayed or linked image. This can lower system performance for applications that rely heavily on this functionality. In practice, it is unlikely to present a heavy burden since the information we are after is either already present in the buffer/disk cache, or would be loaded there soon anyway by the httpd process in order to serve the content.

No bugs are known at this time.


I would like to thank Pm and the rest of the PmWiki team for producing such a cleanly designed and flexible implementation.


  • RanieriArgentini

pmwiki-2.3.7 -- Last modified by {{Simon}}

from IP: ip should be disabled by default for security reasons