Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: My random image isn't as random anymore  (Read 3979 times)

0 Members and 1 Guest are viewing this topic.

aldog

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
My random image isn't as random anymore
« on: November 08, 2007, 07:35:53 pm »

I added a random image script to control my header for my site/gallery, it was VERY random at first, but now it seems to be a lot less random.

http://ad6storieshigh.com/gallery/

Now the thing is, when I first put it on there it was very random, everytime I would refresh the page it would be different, which is exactly what I wanted. But then I started doing different things, updating all my thumbs and making mini thumbs, and enabling some options in my config that were added with modpack and now it's very rare that the image changes.

http://ad6storieshigh.com/gallery/
user: test
pass: pass

Is there a setting I might have enabled that would hinder my random php script?

In case you want to know what my random code is, here you go.
Code: [Select]
<?
/*/////////////////////////////////////////////////////////////////////////////////////////
Created by: Mr_density

Description:
A simple random image generator.
I wrote this script because i had some trouble with other similar scripts that didn't work
as well as this one.

Instructions:
1. Just put this script in the directory containing your images and connect via a
browser to this script. The script wil only show images (jpg, gif, png) not other
file formats.

2. Via an html image tag your can call the script on your site.
syntax: <img src="randompic.php"> or <img src="randompic.php?tnsize=XXX"> (to resize).

Change $config["systempath"] to the path where the images are stored (not the URL and no slash on the end).
Change $config["webpath"] to the path where the images can be found through a webbrowser (include a ending slash).

The options for $config["type"] are "redirect" and "readfile". Redirect will use a "location" header wich will display the image (kind of redirect so). Readfile will read the file from the local hardrive and directly displayed (actually I can not recommend that).
////////////////////////////////////////////////////////////////////////////////////////*/
$config["systempath"] = "./images/logo";
$config["webpath"] = "http://www.ad6storieshigh.com/gallery/themes/oranje/images/logo/";
$config["type"] = "redirect";

if($config["systempath"] != "")
{
    $dircheck = $config["systempath"];
    if (is_dir($dircheck)) //check if it is a valid systempath
    {
$pathtoread = $config["systempath"];
}
else
{
// If not, it creates an error image and displays it
$img = imagecreate(150, 150);
$red = imagecolorallocate($img, 255, 0, 0);
$yellow = imagecolorallocate($img, 255,255, 0);
imagestring($img, 4, 20, 20, "System", $yellow);
imagestring($img, 4, 20, 40, "path", $yellow);
imagestring($img, 4, 20, 60, "error!", $yellow);
imagepng($img);
imagedestroy($img);
exit();
}
}
else
{
$pathtoread = "."; //Dir where this file is stored
}
if($config["webpath"] != "")
{
$url = $config["webpath"];
}
else
{
$explode = explode("/",$_SERVER["REQUEST_URI"]);
$url = "http://".$_SERVER["SERVER_NAME"]."/";
for($i=0;$i<(count($explode)-1);$i++)
{
$url.=$explode[$i]."/";
}
}

$imgdir = opendir($pathtoread);
while($file = readdir($imgdir))
{     
$images[count($images)] = $file; //search all files
}
closedir ($imgdir);

// Removes all non-image files
$tempvar = 0;
for ($i = 0; $images[$i]; $i++)
{
$ext = strtolower(substr($images[$i],-4));
if ($ext == ".jpg" || $ext == ".gif" || $ext == "jpeg" || $ext== ".png" )
{
$images1[$tempvar] = $images[$i];
$tempvar++;
}
}

//Get a random image
$randomnr = rand(0, count($images1)-1);
$img = $images1[$randomnr];

//To resize a image
if(isset($tnsize))
{
$tnsize = (integer) $tnsize;
if (($tnsize < 20) || ($tnsize > 300))
{
// If not, it creates an error image and displays it
$img = imagecreate(150, 150);
$red = imagecolorallocate($img, 255, 0, 0);
$yellow = imagecolorallocate($img, 255,255, 0);
imagestring($img, 4, 20, 20, "Afmetingen", $yellow);
imagestring($img, 4, 20, 40, "kloppen", $yellow);
imagestring($img, 4, 20, 60, "niet!", $yellow);
imagepng($img);
imagedestroy($img);
exit();
}

if ($ext == ".jpg" || $ext == "jpeg")
{
$bigimage = @imagecreatefromjpeg($img);
}
if ($ext == ".gif")
{
$bigimage = @imagecreatefromgif($img);
}
if ($ext == ".png" || $ext == "jpeg")
{
$bigimage = @imagecreatefrompng($img);
}

//Create an empty image of the given size
$tnimage = imagecreate($tnsize, $tnsize);
$darkblue = imagecolorallocate($tnimage, 0,0, 127);
imagecolortransparent($tnimage,$darkblue);

//Calculate the resizing image factor
$sz = getimagesize($img);
$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);
}
else
{
if($config["type"]=="redirect"){
header("Location: ".$url.$img);
}
else if($config["type"]=="readfile"){
readfile($pathtoread."/".$img);
}
else
{
echo "Error: unknown displaytype";
}
}
?>
Thank you in advanced for the help or pointing me in the right direction

I apologize if this turns out to not be related to the modpack, and thank you for making such a great mod.
« Last Edit: November 09, 2007, 08:06:51 am by GauGau »
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: My random image isn't as random anymore
« Reply #1 on: November 08, 2007, 09:00:32 pm »

This definitely isn't related to the modpack nor to CPG in general. Also it's working for me. With 10 tries I've seen all your 7 images. From reading I've first thought you're using an older php version (there you needed to seed the random nr generator). But as said... works smooth for me.

Nibbler

  • Guest
Re: My random image isn't as random anymore
« Reply #2 on: November 08, 2007, 09:30:42 pm »

I see the same problem as you. Firefox is caching the background image. Try as suggested in http://www.webmasterworld.com/forum88/13000.htm.

This is not related to Coppermine, so support (on this board) is limited.
Logged

aldog

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: My random image isn't as random anymore
« Reply #3 on: November 08, 2007, 09:43:40 pm »

ahhh, alright. Thank you stramm for replying so quickly. I'm glad it's working for you!

Nibbler, thank you very very much for figuring out what it is, and thanks for the link.
Logged
Pages: [1]   Go Up
 

Page created in 0.019 seconds with 19 queries.