Re: GD/PNG/Mouseovers

From: Date: Fri, 25 Apr 2003 19:54:34 +0000
Subject: Re: GD/PNG/Mouseovers
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-145308@lists.php.net to get a copy of this message
Your mouseover code is flawed. You should preload all images in the header of your page via Javascript and then use the variables to which you set the preloaded image. Preloading works something like follows: globIMI_001=new Image( 68, 23 ); globIMI_001.src="/Carnage/images/buttons/primary/about.on.png"; globIMO_001=new Image( 68, 23 ); globIMO_001.src="/Carnage/images/buttons/primary/about.png"; Then in the anchor tag you have something like: <a href="/Carnage/about/index.phtml" onmouseover="document['globI_001'].src=globIMI_001.src; window.status='About WOC'; return true;" onmouseout="document['globI_001'].src=globIMO_001.src;" ><img src="/Carnage/images/buttons/primary/about.png" name="globI_001" >border="0" alt="About WOC"/></a> HTH, Rob. -- .---------------------------------------------. | Worlds of Carnage - http://www.wocmud.org | :---------------------------------------------: | Come visit a world of myth and legend where | | fantastical creatures come to life and the | | stuff of nightmares grasp for your soul. | `---------------------------------------------' sysadmin@saginawcontrol.com wrote: > > I have an issue. I have a script that generates two images for a > mouseover link. I use the same script for both images, and I flag it > with an on/off switch. For instance....image.php?text=Test&mode=off > will have the link in the "off" mode. The problem is, it seems to be > 'recreating' these images everytime I mouseover them and it makes the > page load very slowly. Does anyone have any ideas why this is > happening? Here is my code....I'm fairly new to this whole GD stuff so > please be gentle.... > > <? > $s=22; > if($mode=="off") { > header("Content-type: image/png"); > $string = $_GET['text']; > $im = > imagecreatefrompng("/var/www/html/paintball/images/link_off.png"); > $orange = imagecolorallocate($im, 220, 210, 60); > $px = (imagesx($im) - 7.5 * strlen($string)) / 2; > $size = > imagettfbbox($s,0,"/var/www/html/paintball/images/impact.ttf",$text); > $dx = abs($size[2]-$size[0]); > $dy = abs($size[5]-$size[3]); > $xpad=7; > $ypad=7; > #Color Declaration > $backgrnd = ImageColorAllocate($im, 10,109,94); > $shadow = ImageColorAllocate($im, 255,255,255); > $txt = ImageColorAllocate($im, 255,255,255); > #Text Creation > ImageTTFText($im, $s, 0, 28, 31, $txt, > "/var/www/html/paintball/images/impact.ttf", $text); > #Set the Transparent Color > ImageColorTransparent($im, $backgrnd); > ImagePNG($im); > ImageDestroy($im); > } elseif($mode=="on") { > header("Content-type: image/png"); > $string = $_GET['text']; > $im = > imagecreatefrompng("/var/www/html/paintball/images/link_on.png"); > $px = (imagesx($im) - 7.5 * strlen($string)) / 2; > $size = > imagettfbbox($s,0,"/var/www/html/paintball/images/impact.ttf",$text); > $dx = abs($size[2]-$size[0]); > $dy = abs($size[5]-$size[3]); > $xpad=7; > $ypad=7; > #Color Declaration > $backgrnd = ImageColorAllocate($im, 10,109,94); > $shadow = ImageColorAllocate($im, 255,255,255); > $txt = ImageColorAllocate($im, 0,255,0); > #Text Creation > ImageTTFText($im, $s, 0, 28, 31, $txt, > "/var/www/html/paintball/images/impact.ttf", $text); > #Set the Transparent Color > ImageColorTransparent($im, $backgrnd); > ImagePNG($im); > ImageDestroy($im); > } > ?> > > And here is my mouseover code, just in case it is the problem.... > ..... > $i++; > while ($r = mysql_fetch_array($result)) { > $Cat=$r["CategoryID"]; > $Category=$r["Category"]; > $Category=strtoupper("$Category"); > echo "<a href=\"/categories.php?CategoryID=$Cat&UID=$UID\" > onMouseOut=\"RestoreImg()\" onMou > seOver=\"SwitchImg('document.myimg".$i."','document.myimg".$i."','/link. > php?text=$Category&mode=on') > \"><img src=\"/link.php?text=$Category&mode=off\" name=\"myimg".$i."\" > width=\"190\" height=\"36\" a > lt=\"$Category\" border=\"0\"></a><br>"; > $i++; > } > .... > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#145308) next »