Sorry, this page is only available in one language

RandomImage

Suggested dropletname: RandomImage

Published by: Dev4me

This Droplet creates a random image tag from a subdirectory of your Media folder.

$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="'.$width.'" height="'.$height.'"/>';

Required parameters

dir=(folder)
width={imagewidth)
height=(imageheight)

Example

[[RandomImage?dir=rndimg&width=400&height=300]]



« Previous droplet | Overview | Next droplet »