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