<?php
?
/*
|-------------------------------------------------------------------------------------------------------|
| JARD : Just Another Random Displayer |
| Copyright Š 2003 - Alessandro Pellegrini (alessandro.pellegrini@tin.it) |
| You are allowed to use, edit and copy this script. Just leave this copyright n
tice intact. |
|-------------------------------------------------------------------------------------------------------|
| Syntax: <img src=\"rid.php\"> ===> Displays a random image |
| <img src=\"rid.php?tnsize=XXX\"> ===> Displays a random image of a given |
| size. |
|-------------------------------------------------------------------------------------------------------|
| How to use: |
| Put this file in a directory containing all the images you want to display |
| randomly. If there are no-image files, the script won't consider them. |
| Then connect to this script directly from the addres bar or trought an <img> tag in a |
| html page. |
|-------------------------------------------------------------------------------------------------------|
| What this script supports: |
| This script can handle any gif, jpeg, and png image file. There is no bmp supp
rt as long |
| as I think bmp is not a great format for the web. Maybe in a further version I'll add it, or |
| you may add it yourself... |
|-------------------------------------------------------------------------------------------------------|
| Requirements: |
| This script requires GD Libraries. If you want JPG support, you must have inst
lled |
| version 1.6.2 or lower, as long as the JPEG group asked to remove this support
due to |
| Copyright motivations... |
| To use any other support, you must have at least php 4.3.0 on your server... |
|-------------------------------------------------------------------------------------------------------|
| FOR ANY QUESTION OR BUG REPORT, CONTACT ME AT alessandro.pellegrini@tin.it |
|-------------------------------------------------------------------------------------------------------|
*/
// Opens the current folder
// Stores all the files in the directory and counts their number
$names[count($names)] = $file;
// Closes the directory
// Sorts the names alphabetically
// Removes all non-image files
$tempvar=0;
for ($i=0;$names[$i];$i++){
if ($ext==\".jpg\"||$ext==\".gif\"||$ext==\"jpeg\"||$ext==\".png\"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
// Choses one random image
$slika=$names1[$rand_keys[0]];
// Checks if you've choosen to resize the image
// If not, it displays the choosen image
header (\"Location: $slika\");
} else {
// Checks if the given size is valid
$tnsize = (integer) $tnsize;
if (($tnsize<20) or ($tnsize>300)){
// If not, it creates an error image and displays it
$img = ImageCreate(100, 100);
$red = ImageColorAllocate($img, 255, 0, 0);
$yellow = ImageColorAllocate($img, 255,255, 0);
ImageString($img, 4, 20, 20, \"Dimensione\", $yellow);
ImageString($img, 4, 20, 40, \"fornita\", $yellow);
ImageString($img, 4, 20, 60, \"errata!\", $yellow);
ImagePNG($img);
ImageDestroy($img);
}
// We're now sure the image is valid. Now we have to resize it, we're about to use GD libraries.
// It now checks the image format and loads it into a variable
if ($ext==\".jpg\" || $ext==\"jpeg\"){
$bigimage = @ImageCreateFromJPEG($slika);
}
if ($ext==\".gif\"){
$bigimage = @ImageCreateFromGIF($slika);
}
if ($ext==\".png\" || $ext==\"jpeg\"){
$bigimage = @ImageCreateFromPNG($slika);
}
// It now creates an empty image of the given size
$tnimage = ImageCreate($tnsize, $tnsize);
$darkblue = ImageColorAllocate($tnimage, 0,0, 127);
ImageColorTransparent($tnimage,$darkblue);
// It now calculates the resizing image factor
$x = $sz[0];
$y = $sz[1];
if ($x>$y) {
$dx = 0;
$w = $tnsize;
$h = ($y / $x) * $tnsize;
$dy = ($tnsize - $h) / 2;
}else{
$dy = 0;
$h = $tnsize;
$w = ($x / $y) * $tnsize;
$dx = ($tnsize - $w) / 2;
}
// Resizes the image
ImageCopyResized($tnimage, $bigimage, $dx, $dy, 0, 0, $w, $h,$x, $y);
// Displays the image
ImagePNG($tnimage);
// Clears the variables
ImageDestroy($tnimage);
ImageDestroy($bigimage);
}
?>