View Single Post
  #5   Spotlight this post!  
Unread 26-01-2004, 14:46
echos's Avatar
echos echos is offline
Jack of all trades
#1125
Team Role: Programmer
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 61
echos will become famous soon enough
Send a message via ICQ to echos Send a message via AIM to echos Send a message via MSN to echos Send a message via Yahoo to echos
Re: Random code snipets

New version of random image
PHP Code:
<?php
// Last Updated: Sunday, January 26, 2004 at 11:43:45 AM

// *****IPORTANT*****
// GIF support has been disabled due to complications
// of another nature.

/**************************************************/
/* Supported image types                          */
/**************************************************/
/* Input:                                         */
/* PNG                                            */
/* JPEG                                           */
/* WBMP                                           */
/* XBM                                            */
/* XPM                                            */
/*                                                */
/* Output:                                        */
/* PNG                                            */
/* JPEG                                           */
/* GIF (if supported, else defualts to PNG)       */
/**************************************************/

/**************************************************/
/* -Options                                       */
/**************************************************/
/* Image Output type                              */
/*                                                */
/* Desription:                                    */
/* Allows the ability to overide the type of      */
/* image output by the program.                   */
/*                                                */
/* Settings:                                      */
/* auto, png, jpeg, and gif (if supported)        */
/**************************************************/

$imageoutputtype "auto";

/**************************************************/
/* JPEG Quality                                   */
/*                                                */
/* Description:                                   */
/* Allows you to set the compression level of     */
/* JPEGs generated by the program.                */
/*                                                */
/* Settings:                                      */
/* defualt, [0-100] (0 worst and 100 best)        */
/**************************************************/

$jpegquality "defualt";

/**************************************************/
/* NO NEED TO CHANGE ANYTHING BELOW               */
/**************************************************/

//does a check to see if GD is installed and running
/*
if (!isset(imagetypes()))
    {
    die("This server does not have image support.");
    }
*/

if(!isset($imageoutputtype))
    {
    
$imageoutputtype "auto";
    }

if(!
$jpegquality >= && !$jpegquality <= 100)
    {
    
$jpegquality 100;
    }

//read folder
$folder opendir(".");

while (
$file readdir($folder))

$names[count($names)] = $file;

closedir($folder);

//sort file names in array
sort($names);

//remove any non-images from array
$tempvar 0;

for (
$i 0$names[$i]; $i++)
    {
    
$ext=strtolower(substr($names[$i],-4));

    if (
$ext == ".png" || $ext == ".jpg" || $ext == "jpeg" || $ext == "wbmp" || $ext == ".xbm" || $ext == ".xpm")
        {
        
$names1[$tempvar] = $names[$i];
        
$tempvar++;
        }
    }

//random
srand ((double) microtime() * 10000000);
$rand_keys array_rand ($names12);


//random image from array
$rimage $names1[$rand_keys[0]];


//image identification
$imagetype strtolower(substr($rimage,-4));


//image import
if($imagetype == ".png")
    {
    
$image imagecreatefrompng($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "png";
        }
    }

  elseif(
$imagetype == ".jpg" || $imagetype == "jpeg")
    {
    
$image imagecreatefromjpeg($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "jpeg";
        }
    }

  elseif(
$imagetype == ".gif")
    {
    
$image imagecreatefromgif($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "gif";
        }
    }

  elseif(
$imagetype == "wbmp")
    {
    
$image imagecreatefromwbmp($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "png";
        }
    }

  elseif(
$imagetpye == ".xbm")
    {
    
$image imagecreatefromxbm($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "png";
        }
    }

  elseif(
$imagetype == ".xpm")
    {
    
$image imagecreatefromxpm($rimage);

    if(
$imageoutputtype == "auto")
        {
        
$imageoutputtype "png";
        }
    }


//image output
if($imageoutputtype == "gif")
    {
    if(
imagetypes() & IMG_GIF)
        {
        
header("Content-type: image/gif");
        
imagegif($image);
        }
      else
        {
        
header("Content-type: image/png");
        
imagepng($image);
        }
    }

  elseif(
$imageoutputtype == "jpeg" || $imageoutputtype == "jpg")
    {
    if(
imagetypes() & IMG_JPG)
        {
        
header("Content-type: image/jpeg");
        
imagejpeg($image''$jpegquality);
        }
      else
        {
        
header("Content-type: image/png");
        
imagepng($image);
        }
    }

  elseif(
$imageoutputtype == "png")
    {
    
header("Content-type: image/png");
    
imagepng($image);
    }

  else
    {
    
header("Content-type: image/png");
    
imagepng($image);
    }
?>
__________________

Entity Hosting Staff
http://www.entityhosting.com/