|
Cookbook /
AttachImageSizeSummary: Generate width and height attributes for attached images
Version: 20090106
Maintainer: Petko
Discussion: AttachImageSize-Talk
Categories: Images
DescriptionGenerate width and height attributes for attached images The default Attach: markup for attached images doesn't include the image width and height attributes in the HTML tag. This recipe makes it possible to override this, and to automatically set these attributes. InstallationPlace the following code in local/config.php :
function LinkImageSize($pagename, $imap, $path, $alt, $txt, $fmt=NULL) {
global $FmtV, $UploadFileFmt;
if (preg_match('!^(.*)/([^/]+)$!', $path, $match)) {
$pagename = MakePageName($pagename, $match[1]);
$path = $match[2];
}
$upname = MakeUploadName($pagename, $path);
$filepath = FmtPageName("$UploadFileFmt/$upname", $pagename);
$s = @getimagesize($filepath);
$FmtV['$ImageSize'] = @$s[3];
$r = LinkUpload($pagename, $imap, $path, $alt, $txt, $fmt);
$FmtV['$ImageSize'] = '';
return $r;
}
$LinkFunctions['Attach:'] = 'LinkImageSize';
$ImgTagFmt="<img src='\$LinkUrl' alt='\$LinkAlt' title='\$LinkAlt' \$ImageSize />";
$FmtV['$ImageSize'] = '';
NotesSee this message by Pm for limits of such a method. Notably:
Release Notes
See AlsoContributorsThe recipe is written and maintained by Petko. Parts of code from scripts/upload.php by Pm. CommentsSee discussion at AttachImageSize-Talk User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |