View Full Version : Random photo
tommykjensen
10th of March 2004 (Wed), 15:19
Does anybody have a little script that can choose a random thumbnail and copy it to a specific location?
Pekka
10th of March 2004 (Wed), 16:37
Please wait couple of hours.
Pekka
10th of March 2004 (Wed), 18:56
Download an try out http://photography-on-the.net/ee/beta/RC2/snippets.zip
Place the files on your gallery root. Text document and demo file explains usage and parameters.
It's now 3 am here, so I'll comment comments and questions tomorrow morning. This is just a small extra. I'll post a bug fix pack tomorrow, it has duplicate photo removal from combined exhibitions and important bug fix for internal ftp etc.
photocroatia
10th of March 2004 (Wed), 20:12
Thank you very much Pekka,
Another great feature.
Thanks for the work you put into it, I know this will be usefull for my site.
tommykjensen
11th of March 2004 (Thu), 01:06
Thank You very much this is usefull however it was not what I was looking for - but thats my fault I didn't explain it well enough what I wanted to use it for.
What I would like is the ability to put an url such as www.domainname.com/gallery/random.jpg in signatures on a forum like this.
In the background on my server I would run the script once an hour or so in order to change the thumbnail in random.jpg. This way my signature (or avatar) would change fom time to time.
okapi
11th of March 2004 (Thu), 08:02
Download an try out http://photography-on-the.net/ee/beta/RC2/snippets.zip
Place the files on your gallery root. Text document and demo file explains usage and parameters.
It's now 3 am here, so I'll comment comments and questions tomorrow morning. This is just a small extra. I'll post a bug fix pack tomorrow, it has duplicate photo removal from combined exhibitions and important bug fix for internal ftp etc.
great, pekka!
this could be a solution for my problem (latest three photos and random photos on the main page of the gallery).
it works well with an external index.php file as starting page for my site.
but what, if i want to include these snippets into EE's own index-file (indexstyles/1.php for example)?
this obviously does not work.
how could this be done?
tommykjensen
11th of March 2004 (Thu), 11:19
Thank You very much this is usefull however it was not what I was looking for - but thats my fault I didn't explain it well enough what I wanted to use it for.
What I would like is the ability to put an url such as www.domainname.com/gallery/random.jpg in signatures on a forum like this.
In the background on my server I would run the script once an hour or so in order to change the thumbnail in random.jpg. This way my signature (or avatar) would change fom time to time.
Or how about a dynamic signature such as this one
http://www.phpbb.com/phpBB/viewtopic.php?t=149834&highlight=
just with 3-5 microthumbs instead of statistics?
tommykjensen
12th of March 2004 (Fri), 01:14
Here is a simple random photo script. Schedule it to run at the interval of Your choice.
<?php
srand ((double) microtime() * 1000000);
$path = "ee/photos/thumb";
$handle=opendir($path);
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
if (strpos(strtoupper($file), ".JPG") > 0) {
$jpgfiles [] = $file;
}
}
}
$randnum = rand(0,count($jpgfiles));
$image = $path . "/" . $jpgfiles[$randnum];
$im = imagecreatefromjpeg($image);
Imagejpeg($im,'random.jpg',100);
ImageDestroy ($im);
?>
EDIT: Slightly improved code.
http://www.klein-jensen.dk/test/random.jpg
tommykjensen
13th of March 2004 (Sat), 03:14
Once again I have improved the code. It is highly likely that someone better than me can optimize the code.
<?php
$path = "ee/photos/microthumb";
$handle=opendir($path);
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
if (strpos(strtoupper($file), ".JPG") > 0) {
$jpgfiles [] = $file;
}
}
}
$image1 = $path . "/" . $jpgfiles[array_rand($jpgfiles)];
$im1 = imagecreatefromjpeg($image1);
$ix1 = imagesx($im1);
$iy1 = imagesy($im1);
$image2 = $path . "/" . $jpgfiles[array_rand($jpgfiles)];
$im2 = imagecreatefromjpeg($image2);
$ix2 = imagesx($im2);
$iy2 = imagesy($im2);
$image3 = $path . "/" . $jpgfiles[array_rand($jpgfiles)];
$im3 = imagecreatefromjpeg($image3);
$ix3 = imagesx($im3);
$iy3 = imagesy($im3);
$image4 = $path . "/" . $jpgfiles[array_rand($jpgfiles)];
$im4 = imagecreatefromjpeg($image4);
$ix4 = imagesx($im4);
$iy4 = imagesy($im4);
$height = $iy1 + $iy3 + 3;
if ( $iy2 + $iy4 > $height ) {
$height = $iy2 + $iy4 + 3;
}
$heightl1 = $iy1;
if ( $iy2 > $iy1 ) {
$heightl1 = $iy2;
}
$heightl2 = $iy3;
if ( $iy4 > $iy3 ) {
$heightl2 = $iy4;
}
$length = $ix1 + $ix2 + 3;
if ( $ix3 + $ix4 > $length ) {
$length = $ix3 + $ix4 + 3;
}
$offsety1 = 0;
$offsety2 = 0;
$offsety3 = 0;
$offsety4 = 0;
if ( $iy1 < $iy2 ) {
$offsety1 = ($iy2 - $iy1 ) / 2;
}
if ( $iy2 < $iy1 ) {
$offsety2 = ($iy1 - $iy2 ) / 2;
}
if ( $iy3 < $iy4 ) {
$offsety3 = ($iy4 - $iy3 ) / 2;
}
if ( $iy4 < $iy3 ) {
$offsety4 = ($iy3 - $iy4 ) / 2;
}
$offsetx1 = 0;
$offsetx2 = 0;
$offsetx3 = 0;
$offsetx4 = 0;
if ( $ix1 < $ix3 ) {
$offsetx1 = ($ix3 - $ix1 ) / 2;
}
if ( $ix2 < $ix4 ) {
$offsetx2 = ($ix4 - $ix2 ) / 2;
}
if ( $ix3 < $ix1 ) {
$offsetx3 = ($ix1 - $ix3 ) / 2;
}
if ( $ix4 < $ix2 ) {
$offsetx4 = ($ix2 - $ix4 ) / 2;
}
$im = imagecreatetruecolor($length,$height);
imagecopy($im, $im1, 1 + $offsetx1,1 + $offsety1,0,0,$ix1, $iy1);
imagecopy($im, $im2, 1 + $offsetx1*2 + $ix1,1 + $offsety2,0,0,$ix2, $iy2);
imagecopy($im, $im3, 1 + $offsetx3,2 + $heightl1 + $offsety3,0,0,$ix3, $iy3);
imagecopy($im, $im4, 1 + $offsetx3*2 + $ix3 + $offsetx4,2 + $heightl1 + $offsety4,0,0,$ix4, $iy4);
Imagejpeg($im,'random4thumbs.jpg',100);
Imagejpeg($im,'',100);
ImageDestroy ($im);
ImageDestroy ($im1);
ImageDestroy ($im2);
ImageDestroy ($im3);
ImageDestroy ($im4);
?>
Will generate this:
http://www.klein-jensen.dk/test/random4thumbs.jpg
vBulletin® v3.6.12, Copyright ©2000-2012, Jelsoft Enterprises Ltd.