Random Image

astricia

Quote from: astricia on June 15, 2015, 11:36:38 AM
Now if I could figure out how to extract the path from the image URL to display underneath the picture (only the part which describes the year and party) and use it in a link wrapped around the image and path to make it link straight to the foldergallery...

Figured it out... woohoo! :D Actually just some basic PHP string functions, but tricky for me as I don't do this very often.

Thanks everyone for your help!

astricia

Quote from: BlackBird on June 15, 2015, 10:54:38 AM
Quote from: astricia on June 15, 2015, 10:04:35 AM
Correction - the version from Blackbird does not "always" use the fg-thumbs folder, but it includes them as well.

Are you sure that you read the docs?

Oops - no, admittedly, I did not read to the end. So, yes, it works now to display only images from the thumbs-folders.

Also thank you for the trick with different images, Manuela. It works the same way with the droplet from BlackBird.

Now if I could figure out how to extract the path from the image URL to display underneath the picture (only the part which describes the year and party) and use it in a link wrapped around the image and path to make it link straight to the foldergallery...

BlackBird

Quote from: astricia on June 15, 2015, 10:04:35 AM
Correction - the version from Blackbird does not "always" use the fg-thumbs folder, but it includes them as well.

Are you sure that you read the docs?
[url=http://wbaddons.webbird.de]http://wbaddons.webbird.de[/url] [url=http://www.WebsiteBaker.org/forum/index.php/topic,27476.msg189845.html#msg189845]Don't miss this[/url]

DarkViper

Quote from: astricia on June 15, 2015, 09:56:27 AM
But - I only can get ONE random picture this way. If I call the same droplet 2 or 3 times, the same random picture will display 2 or 3 times. I guess in order to have 2 or 3 DIFFERENT random pictures, I need to create 3 almost identical droplets, but with different names and then use those...?

This is result of the kind what droplets are and how it works. General droplets are a simple Search&Replace. All identical droplet tags will be replaced with the result of the first founded at once.
But don't worry... you can get multiply, different images anyway. ;-)
All you have to do is modify the droplet tags a little bit.

[[RandomImageFromTree?dir=foldergalery/archive/&x=1]]
[[
RandomImageFromTree?dir=foldergalery/archive/&x=2]]
[[
RandomImageFromTree?dir=foldergalery/archive/&x=3]]

'x' is a unused argument.. it has no effect to the droplet itself.. but It makes each droplet tag unique. So each of them will be executed and you get different results of each.
A little trick with a good effect. ;-)

Manuela
[url=http://www.youtube.com/watch?v=tmzDAz6ZvFQ]Der blaue Planet[/url] - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen[br]
[i]"You have to take the men as they are... but you can not leave them like that !" :-P [/i]
[i]Das tägliche Stoßgebet: [b]Oh Herr, wirf Hirn vom Himmel ![/b][/i]

astricia

Correction - the version from Blackbird does not "always" use the fg-thumbs folder, but it includes them as well. But it restricts the height and width of the pictures, so if it takes one of the bigger versions, which are not square formatted, then it will stretch or compress it... which makes it look funny.

So I suppose I prefer the version from Manuela...

astricia

Thanks both of you!!! I tried both solutions - the droplet from BlackBird and the solution from DarkViper. Both of them work, and are quite fast. Interestingly enough the solution from BlackBird always uses the fg-thumbs folders (and thus produces thumbnails), while DarkViper's version uses the bigger versions of the pictures.

But - I only can get ONE random picture this way. If I call the same droplet 2 or 3 times, the same random picture will display 2 or 3 times. I guess in order to have 2 or 3 DIFFERENT random pictures, I need to create 3 almost identical droplets, but with different names and then use those...?

Also, I need to figure out how to extract part of the URL to display as text underneath those pictures, so that it indicates from which year and which party in that year these pictures are from. And possibly even link the image to the foldergallery of that album...

Thanks,
Astricia

Gast

Quote from: DarkViper on June 14, 2015, 03:41:31 PM
I don't start in 'media/' ;-)

not you, but i (for a test - Droplet-Call without Parameters)

DarkViper

Quote from: jacobi22 on June 14, 2015, 02:24:49 PM
1. only a comment...  it makes problems and is not recommened, if you start directly in the media folder
I don't start in 'media/' ;-)
I use WB_PATH.MEDIA_DIRECTORY.'/'.$dir
So it's possible to use any subdir or subsubdir of media to start.
The only mandatory is, that the start directory must be somewhere behind media/.

Manuela
[url=http://www.youtube.com/watch?v=tmzDAz6ZvFQ]Der blaue Planet[/url] - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen[br]
[i]"You have to take the men as they are... but you can not leave them like that !" :-P [/i]
[i]Das tägliche Stoßgebet: [b]Oh Herr, wirf Hirn vom Himmel ![/b][/i]

Gast

Quote from: DarkViper on June 14, 2015, 11:50:54 AMTake this example and modify it to your concrete needs.

1. only a comment...  it makes problems and is not recommened, if you start directly in the media folder
2. the return of array_rand is only a key, so it needs a little modification


DarkViper

#9
Quote from: astricia on June 13, 2015, 12:50:53 PM
The project I am currently working on (a relaunch for a disco) has almost 30,000 pictures altogether, sorted by year (2003-2014) and about 20-30 albums per year. It is very neat to show all these pictures with the foldergallery. But on the homepage I would like to show 2 or 3 random pictures from all these pictures. Ideally even with the name of the folder they are in and a link to the entire folder...
30.000 pics is heavy....  if you think straight.. ;)
But it's possible to scan all of these images very fast. the solution for, you gave it as you described how the pics are organises.
It's not needed to scan all of these 30.000 pics. Simply step by step scan for folders and choose one of it. In the last folder only you must scan for all files located in this folder and take one of them. This kind of scanning is very fast.

Take this example and modify it to your concrete needs.
<?php

//:get a random image URL from folder tree
//:Commandline to use: [[RandomImageFromTree?dir=foldergalery/archive/]]

    
$sRetval 'URL to a "NoImageAvail" pic';
    
$sStartFolder rtrim(str_replace('\\''/'WB_PATH.MEDIA_DIRECTORY.'/'.$dir), '/').'/';
    
$sStartUrl rtrim(str_replace('\\''/'WB_URL.MEDIA_DIRECTORY.'/'.$dir), '/').'/';
// break if folder not exists or is not readable
    
if (!is_readable($sStartFolder)) { return $sRetval; }
// save current working directory
    
$sOldDir getcwd();
// set working directory to $sStartFolder
    
chdir($sStartFolder);
// scan for 'years'-folder
    
if (($aYears glob('*'GLOB_ONLYDIR|GLOB_NOSORT|GLOB_MARK))) {
        
// randimize one year if one at least is available
        
$iRandomYear array_rand($aYears1);
        
// scan for 'category'-folders
        
if (($aCategories glob($aYears[$iRandomYear].'*'GLOB_ONLYDIR|GLOB_NOSORT|GLOB_MARK))) {
            
// randimize one category if one at least is available
            
$iRandomCategory array_rand($aCategories1);
            
// scan for images inside selected category
            
if (($aImages glob($aCategories[$iRandomCategory].'*{png,jpg,gif,PNG,JPG,GIF}'GLOB_NOSORT|GLOB_BRACE))) {
                
// randimize one image if one at least is available
                
$iImage array_rand($aImages1);
                
// build full URL for this image
                
$sRetval $sStartUrl.$aImages[$iImage];
            }
        }
    }
// restore working directory
    
chdir($sOldDir);
// now return the result
    
return $sRetval;

Edit: corrected retval of array_rand()
( no guaranty, no warranty... test it..)

Manuela
[url=http://www.youtube.com/watch?v=tmzDAz6ZvFQ]Der blaue Planet[/url] - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen[br]
[i]"You have to take the men as they are... but you can not leave them like that !" :-P [/i]
[i]Das tägliche Stoßgebet: [b]Oh Herr, wirf Hirn vom Himmel ![/b][/i]

Gast

google is your friend  ;-)

here the Droplet RandomOrLatest from Bianka aka BlackBird

but dont forget: if you have a lot of picture folders, the droplet scan a lot of folders


astricia

Of course I know the droplet "RandomImage" and I know that it is not possible to show random pics from multiple folders.

But reading the above thread, I figured that somebody (BlackBird?) had found a solution to this problem and had posted it at the time, but later deleted it for whichever reason. That's why I'm asking ...

The project I am currently working on (a relaunch for a disco) has almost 30,000 pictures altogether, sorted by year (2003-2014) and about 20-30 albums per year. It is very neat to show all these pictures with the foldergallery. But on the homepage I would like to show 2 or 3 random pictures from all these pictures. Ideally even with the name of the folder they are in and a link to the entire folder...

Anyone has an idea?

Thanks,
Astricia

Gast

here the droplet called "RandomPicture", its a Part of the actual WB-2.8.3-SP4-Download-Package incl SP4, all droplets in this package are repaired and testit. Its not possible with this droplet, to show random pics from multiple folders

german: Hier das aktuelle Droplet "RandomPicture" aus dem aktuellem WB-2.8.3-SP4-Paket. Alle Droplets in diesem Paket  wurden repariert und getestet. Es ist mit diesem Droplet nicht möglich, Bilder aus verschiedenen Ordnern zu zeigen

Dropletname: RandomImage

Beschreibung / Description: Get a random image from a folder in the MEDIA folder.

Droplet-Aufruf / Usage:
[[RandomImage]] - show a random image in media-directory
[[RandomImage?dir=bakery/images/item2]] - show a random image in media-subdirectory

Code
$dir = ( (isset($dir) && ($dir!='') ) ? $dir : '');
$folder=opendir(WB_PATH.MEDIA_DIRECTORY.'/'.$dir.'/.');
$names = array();
while ($file = readdir($folder))  {
   $ext=strtolower(substr($file,-4));
   if ($ext==".jpg"||$ext==".gif"||$ext==".png"){
       $names[count($names)] = $file;
   }
}
closedir($folder);
shuffle($names);
$image=$names[0];
$name=substr($image,0,-4);
return '<img src="'.WB_URL.MEDIA_DIRECTORY.'/'.$dir.'/'.$image.'" alt="'.$name.'" width="95%" />';




astricia

Sorry, just realized this is the English part of the forum. I currently have the same problem - I need a droplet "Random Image" which also looks through the subfolders and picks any picture from any of the many subfolders.

Obviously there was a solution in this thread, but it has been removed. Can somebody help me please?

Thanks,
Astricia

astricia

Leider wurden hier offensichtlich Beiträge entfernt. Ich habe gerade den gleichen Wunsch - ein Droplet "Random Image", das auch Subfolder durchsucht. Kann mir da jemand helfen?

LG,
Astricia


hansis100


hansis100


hansis100

Hello!

I have tested a lot of droplets for random Images, but nothing found.
I need a droplet for random images that can include subfolders.
example
/media/photos/
|-- /photos1/
         |-- photo1.jpg
         |-- photo2.jpg
|-- /photos2/
         |-- photo3.jpg
         |-- photo4.jpg


anyone knows a droplet?

thx.
hansi