ExtendedImagesWithLinks
<< Random Incl | Cookbook-V1 | Netflix Include >>
Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.
Goal
A script allows to add images (with a relative path) which are linked.
Solution
solved
Code should be look like this:
[:imageincllink http://www.somedomain.cc/;/path/to/image.jpg:]
or [:imageincllink /path/to/link.html;/path/to/image.jpg:]
or even with anchors [:imageincllink #top;/path/to/image.jpg:]
( anchor can be defined with [[#name]] )
# function to retrive width and height of the included image
function getimagedimension($path)
{
if($path!="")
{
$fullpath = getcwd().trim($path);
$sizearray=getimagesize($fullpath);
return $sizearray[3];
}
}
# include linked image
$BrowseDirectives['/\\[:imageincllink (.*):\\]/e'] = 'imginclink("$1")';
function imginclink($urlimg) {
$arrayt = explode (";",$urlimg);
$urlimgstr = '<a href="'.$arrayt[0].'"><img src="'.$arrayt[1].'" '.getimagedimension($arrayt[1]).'" border="0" alt=""></a>';
return Keep($urlimgstr);
}
Discussion
I don't want do this
[[http://www.domain.cc/path ThisSite:/path/to/image.jpg]]
because in the result is an unwanted <a class="urllink" ...]
and
i want to get the size of the image by php-script and add width="..." and height="..." in the code ...
See Also
Only for images with relative paths: (include in local/config.php)
# include image with relative path, width, height but no <br> at the end
$DoubleBrackets['/\\[:relinclnobr (.*):\\]/e'] = "Keep(RelInclNoBr('$1'))";
function RelInclNoBr($img) {
$imgstr = "<img src=\"".$img."\" ".getimagedimension($img)." border=\"0\" alt=\"\">";
return $imgstr;
}
# include image with relative path, width, height with <br> at the end
$DoubleBrackets['/\\[:relincl (.*):\\]/e'] = "Keep(RelIncl('$1'))";
function RelIncl($img) {
$imgstr = "<img src=\"".$img."\" ".getimagedimension($img)." border=\"0\" alt=\"\"><br>";
return $imgstr;
}
Usage:
[:relincl /path/to/image.jpg :]
or
add
RelIncl
on a single line in your local/localmap.txt
and
Use: RelIncl:/path/to/image.jpg
History
Comments & Bugs
Contributors
Copyright
Always GPL pmwiki-2.5.2 -- Last modified by {{el}}