#####I have included the 2 functions MSFPhover and MSFPpreload so it works
#####without already having these declared elsewhere
#####you should also note that you will need the php gd extension library
#####on your server -- if you are sorted you can use this script with jpEg, gif
#####and png formats -- works fine with all
#####use: echo ImageGreyOver('image.gif','http://link') to define your image source
#####and its link -- the image should, if referenced in this manner, be in the
#####same directory as the two php files
#####NB:I have enclosed the main html-generating php file in html echoes to make it
#####easy to create a freestanding file for testing -- call this first part
#####file_something.php3
#####alternatively, strip the html echoes out
#####(NOT the echo ImageGreyOver('image.gif','http://link'))
#####and chuck in your script
#####HTH
echo "";
echo "";
echo "";
function ImageGreyOver($src,$href,$imageprops="border=0",$linkprops=""){
global $giop;
$giop++;
$greysrc="greyimggif.php3?src=$src";
$size=GetImageSize($src);
return "\n\n\n\n".
" document['MSFPnav".$giop."'].src=MSFPnav".$giop."h.src\" onmouseout=\"if(MSFPhover)
document['MSFPnav".$giop."'].src=MSFPnav".$giop."n.src\">src=\"".$greysrc."\" $imageprops name=\"MSFPnav".$giop."\">";
}
echo ImageGreyOver('image.gif','http://link');
echo " ";
echo "";
echo "";
?>
#####save as file greyimggif.php3 in same directory
#this file outputs a grey version of specified image
#use of this file:
# in the image tag,
# where imagesrc is the source of the original colour version
# where colno is 0 for grey, 1 for red, 2 green, 3 blue
function MakeColoursGrey($im,$col){
$total=ImageColorsTotal($im);
for($i=0;$i<$total;$i++){
$old=ImageColorsForIndex($im,$i);
#trying to keep proper saturation when converting
$commongrey=(int)($old[red]+$old[green]+$old[blue])/3;
if(!$col){
ImageColorSet($im,$i,$commongrey,$commongrey,$commongrey);
}elseif($col==1){
ImageColorSet($im,$i,$commongrey,0,0);
}elseif($col==2){
ImageColorSet($im,$i,0,$commongrey,0);
}elseif($col==3){
ImageColorSet($im,$i,0,0,$commongrey);
}
}
}
$img=imagecreatefromgif($src);
#change the colours to grey
MakeColoursGrey($img,$col);
#send the http header, this outputs an image of type gif
Header("Content-Type: image/gif");
#send the image
ImageGif($img);
?>
###### end of greyimg.php3