>>  Site Map >>  Forums >>  Blocks 6x

Forum module - topics in forum:



Blocks 6x - Discussions regarding PHP-Nuke Blocks.



Random picture block

After talking about random movie blocks the other day - I am sure I have seen a random picture block add-on. Does this require a dbase of the pictures you want to use or can you create a folder with certain pictures in that the block can read from?






Both will do, you can either build a database of your pictures or have a script pull a random picture for you from all the pictures in a certain folde.
    Building A Database:
    This method would be my prefered one becasue i can store aditional informaiton about each picture, like who, when last accessed it (or who it was randomly show to last), a discription of the picture and how many times it has been shown, clicked on.

  1. Random image From All in a Folder:
    Well this is a litle more simple to exicute but you wouldnt really have any stats or info about the pictue, basicly just show the picture itsself, here is an example of a piece of code that will do it for you:
    Code: :
    <?php
    $imgdir = "images/admin";
    $dh    = opendir($imgdir);
    while (false !== ($file = readdir($dh)))
       {
         if (preg_match('/\.gif$/i', $file)) // sanning for .gif files only
            {
            $filelist[] = $file;
            }
       }

    srand((double)microtime()*1000000);
    $picnum = rand(0, sizeof($filelist) - 1);

    $content .= "<IMG SRC='$imgdir/$filelist[$picnum]'>";

    echo "$content";

    closedir($dh);
    ?>

    That will look in the $imgdir directory for all the .jpg images and randomly pic one, save this to a file called image.php in the root directory (ie. where the config.php is and call it from your browser, it will randomly pic and display an image from the images/admin folder.

    To use this in a block edit the $imgdir variable to the folder where your images are and remve the line
    Code: :
    echo "$content";

    This was only here so when you tested it from outside a block it worked, the block will out put the $content variable on its own.

Have Fun Very Happy






Thanx Dashe Very Happy

I also have found a random pic block. I'm not worried about stats and stuff - just a gizmo for showing some thumbnails that's all.

I'll let you know how all this goes and give you all the url when it's done! Shocked






This block is great Dashe. What I wanted to know was. How do I make the file a specific size. In my case I would like it to be 120wx200h and I also wanted to be able for the user to click on it and then it enlarges the whole image to the org. size. Is this hard to do?

Thanks
Shedrock






Well making the link is easy just change the content variable so it has a <A tag on it and link it to the image. Might have some javascript in the <A tag to make it apear in a pop up.

If you leave the images the original size you can resize them to 120 x 120 on the fly with GD but unfortunalty I am only getting my head around GD at the moment myself in developing my JAG Gallery, so I can really help you there.

Check out www.phpbuilder.com and search the Forums for on the fly resize you should find some snippets that you coudl use but I will let you know as soon as i sort it out myself.

Dont hold your breath though could be a couple of weeks Wink




Attention! You are currently viewing sitemap page!
We strongly suggest to look at original content

Search from web

Valid HTML 4.01 Valid CSS