Hi All 1. I debugged further, looks line "$directory = opendir("himg");" is taking lot of time. The himg folder is in same path as that of page.tpl.php. Not sure why ths problem is coming. Any input? 2. I just commented line "$directory = opendir("himg");" and declared an array and harcoded file names. 3. After that I faced the problem with below two lines. header('Content-Type: image/jpeg'); imagejpeg($image); With this it is printing some junk characters in screen and after that it is printing page.tpl.php file. Any suggestions how to get-rid of this problem. Regards, Austin ---------------------- Hi All Thanks for your input. Out of curosity, I just put some PHP code (as shown below in blue and red color) , and independently it is rotating images present in folder "himg" properly. I have a sub-theme myzen (based on Zen theme). I have put page.tpl.php in myzen\templates folder. I added same code to page.tpl.php in head section. When I access site, it takes more time and gets error "Time exceeds" and "SQL server gone away". Can somebody point out whats gooing wrong here? <?php function endswith($string, $test) { $strlen1 = strlen($string); $testlen = strlen($test); if($strlen1 < $testlen) return FALSE; $diff = $strlen1 - $testlen; $strend = substr($string, $diff); return ($strend == $test); } $directory = opendir("himg"); while ( FALSE !== ($file = readdir( $directory )) ) { if(endswith($file, "jpg")) { $files[] = $file; } } //Calculate a random value $which = rand(0,sizeof($files)-1) ; $imagepath="himg/" . $files[$which]; //print $which; $image=imagecreatefromjpeg($imagepath); $imgheight = imagesy($image); $imgcolor = imagecolorallocate($image, 255, 255, 55); imagestring($image, 30, 110, $imgheight - ($imgheight - 65), "Example Text..", $imgcolor); header('Content-Type: image/jpeg'); imagejpeg($image); ?> Regards, Austin