Forum

Results 1 to 11 of 11

Thread: Banners

  1. #1
    Join Date
    December 2009
    Location
    Maryland
    Posts
    9

    Banners

    I noticed I can cycle different banners. I can't quite figure out how to do that. Could you inform me?

  2. #2
    Join Date
    December 2009
    Location
    France
    Posts
    25
    Use a PHP script to generate different images. Each time TS will try to access to the PHP image, it will change the image displayed.

  3. #3
    Join Date
    December 2009
    Location
    Maryland
    Posts
    9
    dont suppose you have one of those scripts on hand? if not no problem

  4. #4
    Join Date
    December 2009
    Location
    France
    Posts
    25
    You have a website with PHP I suppose.

    Do you want a random image (example : 1,4,2,4,2,1,3, ...) or a cycle of images (example : 1,2,3,4,1,2, ...) ?

  5. #5
    Join Date
    May 2009
    Location
    canada
    Posts
    21
    displays a random image from an image folder

    PHP Code:
    <?php
    //2009 Mitchell Trout
    //Created: June 20, 2009
    //Fuction: displays a random signature from an image folder

    //make sure the browser knows its an image and not to save it because it will change every time
    header("Content-type: image/png");
    header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    header('Expires: Fri, 2 Mar 1990 08:52:00 GMT');
    header('Pragma: no-cache');

    $image_dir 'images';
    $count 0;
    if (
    $handle opendir($image_dir)) {
        
    $retval = array();
        while (
    false !== ($file readdir($handle))) {
            if ((
    $file <> ".") && ($file <> "..")) {
            
    $retval[$count] = $file;
            
    $count $count 1;
                }
        }

        
    closedir($handle);
    }
    shuffle($retval);
    $current_image $retval[0]; 

    $im imagecreatefromjpeg($image_dir "/" $current_image);

    imagepng($im);
    imagedestroy($im);
    ?>
    put this script in any directory on your webserver and create an images folder next to it. put the images you want to randomize in the images folder.
    link to the php file like it was an image.

  6. #6
    Join Date
    December 2009
    Location
    Behind the sofa...
    Posts
    24
    Be sure to have the images saved as jpeg files!

  7. #7
    Join Date
    December 2009
    Location
    France
    Posts
    25
    If you only use png images, for example, you must change imagecreatefromjpeg by imagecreatefrompng. It's the same for gif.

  8. #8
    Join Date
    May 2009
    Location
    canada
    Posts
    21
    Quote Originally Posted by Sharpe49 View Post
    If you only use png images, for example, you must change imagecreatefromjpeg by imagecreatefrompng. It's the same for gif.
    yea i forgot my script will only accpet JPEGs and outputs the images as a PNG when its finished. i was working on one that will take any image type but havnt completed it yet(probably never will).

    if you want to change this you must alter the line:
    PHP Code:
    header("Content-type: image/png"); 
    this will change the output format

    and the line:
    PHP Code:
    $im imagecreatefromjpeg($image_dir "/" $current_image); 
    changing imagecreatefromjpeg to
    • imagecreatefromgd2
    • imagecreatefromgd2part
    • imagecreatefromgd
    • imagecreatefromgif
    • imagecreatefromjpeg
    • imagecreatefrompng
    • imagecreatefromwbmp
    • imagecreatefromxbm
    • imagecreatefromxpm

    will allow you to use different image formats as the source. note: all source images must be of the same filetype.

    should also mention that PHP needs to be compiled with the GD library for you to use the image functions.

  9. #9
    Join Date
    December 2009
    Location
    France
    Posts
    25
    Maybe you can try to make a function which will recognize the extension of the image with PCRE (regex) and then choose which "imagecreatefrom" function to use ?

  10. #10
    Join Date
    May 2009
    Location
    canada
    Posts
    21
    Quote Originally Posted by Sharpe49 View Post
    Maybe you can try to make a function which will recognize the extension of the image with PCRE (regex) and then choose which "imagecreatefrom" function to use ?
    that was the idea. never got around to doing it.

  11. #11
    Join Date
    May 2009
    Location
    canada
    Posts
    21
    PHP Code:
    <?php
    //2009 Mitchell Trout
    //Created: December 22, 2009
    //Fuction: displays a random image from an image folder

    //make sure the browser knows its an image and not to save it because it will change every time
    header("Content-type: image/png");
    header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
    header('Expires: Fri, 2 Mar 1990 08:52:00 GMT');
    header('Pragma: no-cache');

    //new way - it knows how many images there are
    $image_dir 'images';
    $count 0;
    if(
    $handle opendir($image_dir))
    {
        
    $retval = array();
        while (
    false !== ($file readdir($handle)))
        {
            if ((
    $file <> ".") && ($file <> ".."))
            {
                
    $retval[$count] = $file;
                
    $count $count 1;
            }
        }

        
    closedir($handle);
    }
    shuffle($retval);
    $current_image $retval[0];

    //find extention and use matching create function
    $ext substr($current_imagestrrpos($current_image'.') + 1);

    switch(
    $ext)
    {
        case 
    'jpg':
            
    $im imagecreatefromjpeg($image_dir "/" $current_image);
            break;
            
        case 
    'jpeg':
            
    $im imagecreatefromjpeg($image_dir "/" $current_image);
            break;
            
        case 
    'png':
            
    $im imagecreatefrompng($image_dir "/" $current_image);
            break;
            
        case 
    'gif':
            
    $im imagecreatefromgif($image_dir "/" $current_image);
            break;
            
        default:
            
    //invalid file extention - create error image
            
    $im  imagecreatetruecolor (10020);
            
    $bgc imagecolorallocate($im255255255);
            
    $tc  imagecolorallocate($im000);
            
    imagefilledrectangle($im00200200$bgc);
            
    imagestring($im155'Error loading ' $imgname$tc);
    }

    imagepng($im);
    imagedestroy($im);
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Banners...
    By MaXXimus in forum Suggestions and Feedback
    Replies: 0
    Last Post: December 22nd, 2009, 11:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •