[support] How to show random images

Austin Einter austin.einter at gmail.com
Sat Feb 26 04:21:42 UTC 2011


Thanks Kamal
Tried same.., looks working fine.

As you mentioned how to give captions in image....

Regards
Austin
On Sat, Feb 26, 2011 at 9:49 AM, Kamal Palei <palei.kamal at gmail.com> wrote:

> Its working now.
>
> Trick was  comment below
>
>
> //header('Content-Type: image/jpeg');
>
> //imagejpeg($image);
>
> and use
>
>
> <img src="<?php print $imagepath ?>" />
>
> *However how do I add caption to images? Any input please?*
>
> Regards,
> Austin
>
>
>   On Sat, Feb 26, 2011 at 9:17 AM, Austin Einter <austin.einter at gmail.com>wrote:
>
>>   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
>>
>> --
>> [ Drupal support list | http://lists.drupal.org/ ]
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110226/ffa51682/attachment-0001.html 


More information about the support mailing list