Random image script that works?

Hello All,

First of all, I've searched the entire forum but I am not able to get this working. Here is my situation, my zenphoto (latest) script resides in /album/ and I want to display random images on my /index.php (which resides outside the zen folder)
I've tried the script by others that I found throughout the forum but no luck. I either get an error or a blank page. Can someone provide me with a script that would perform what I have just stated?

Thanks for your time :)

Comments

  • acrylian Administrator, Developer
    A random images function is already included in zenphoto 1.1.2 That's why you get a blank page if you call it again within your theme: http://www.zenphoto.org/trac/wiki/TemplateFunctionsGuide

    Sorry ,I didn't get on what page exactly you want the latest images to show. The zp index page or that of your existing website?
  • Thanks for the reply :)

    I am trying to add RANDOM images to my index page outside the album folder, not the zp index.
  • The following seems to work. (I have not done extensive testing.)

    in your /index.php file insert the following php lines:
    `define('ZENFOLDER', 'album/zp-core');

    require_once(ZENFOLDER . "/template-functions.php");`

    For an example visit http://testalbum-2.sbillard.org/. The index.php file for this page is follows. (My zenphoto install is in a folder named zenphoto.)

    `<?php <br />
    define('ZENFOLDER', 'zenphoto/zp-core');

    require_once(ZENFOLDER . "/template-functions.php");

    function printHeadingImage($randomImage) {

    $randomImageURL = 'zenphoto' . getURL($randomImage);

    print "image
    $randomImage->getSizedImage(getOption('image_size')) .

    "' alt="random image"n" . $randomImage->getTitle() .

    '" />
    ';

    echo '';

    }

    header ('Content-Type: text/html; charset=' . getOption('charset'));

    ?>





    Test Index





    <?php <br />
    $img = getRandomImages();

    printHeadingImage($img);

    ?>



    `
  • I am receiving the following error now, I am not an PHP expert, so I have no clue what would be the problem.
    Here is my server info: Apache/2.0.59 (Win32) PHP/5.2.0RC3-dev

    Parse error: parse error, unexpected T_STRING in C:\Program Files\Apache Group\Apache2\htdocs\site\random.php on line 6
  • First, after some experimenting, the proper lines to add to your index.php file are:

    `define('ZENFOLDER', 'zp-core');

    define('WEBPATH', 'zenphoto');

    require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");`

    this replaces the two lines in my post above.

    As to your error message. What it is saying is that there is a syntax error in your file named random.php. You would have to post the contents of your random.php file for us to help you there.
  • Hello sbillard.

    All I am doing is copying and pasting your code to random.php, so i haven't added anything else. Here is my random.php and I am still getting T_STRING error

    <?php
    define('ZENFOLDER', 'zp-core');
    define('WEBPATH', 'album');
    require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");
    function printHeadingImage($randomImage) {
    $randomImageURL = 'zenphoto' . getURL($randomImage);
    print "<img src='".
    $randomImage->getSizedImage(getOption('image_size')) .
    "' alt="random image"n" . $randomImage->getTitle() .
    '" />
    ';
    echo '</div>';
    }
    header ('Content-Type: text/html; charset=' . getOption('charset'));
    ?>
    <html>
    <head>
    <title>Test Index</title>
    </head>
    <body>
    <?php
    $img = getRandomImages();
    printHeadingImage($img);
    ?>
    </body>
    </html>
  • You have imbalanced quotation marks in your print statement.
  • I am back :)

    I placed the random image script on the index page of my website and it's working great! One thing though, it is loading extremely slow because it seem like it's loading the full image but as a thumbnail size. How can I allow the script to display the cached copy of the pictures instead of the original picture? So, the random image that is being displayed is the cached (smaller) image but still links to the original picture in zenphoto?

    Again, here is the script I am using

    `

    <?php<br />
    define('ZENFOLDER', 'zp-core');

    define('WEBPATH', 'album');

    require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");

    header ('Content-Type: text/html; charset=' . getOption('charset'));

    ?>





    Test Index





    <?php<br />
    $randomImage = getRandomImages();

    $randomImageURL = getURL($randomImage);

    echo "image
    $randomImage->getSizedImage(getOption('image_size')) .

    "' alt="random image"n" . $randomImage->getTitle() .

    '" />
    ';

    ?>





    `
  • The script will display a chached image if one already exists. Otherwise it will resize the full image and place it in the cache. You could change the script to display the default sized image by changing the line:

    `$randomImage->getSizedImage(getOption('image_size')) .`

    To use `getDefaultSizedImage()` instead. Then it will use the same size image as your image pages. You can run the pre-cache image scripts to insure that all the images have cached this size.
  • this is just getting a random image right? not getting a random image for album thumbs, right?
  • Yes, it just puts out an image. You can change the code that puts out the `href` to put out a thumb instead if that is what you want, or you can just change the parameter to `getSizedImage` to the thumb size. Also change the reference to the album instead of the image.
  • I have used this code, but I would like to know how you would get the height and with into the image tag (so that it validates as XHTML)? I have tried the getDefaultWidth() and getDefaultHeight() functions, but they do not seem to work in this context. sbillard, could you please show how one would do this? Also I want to show a link to the album.
  • Take a look at the function references on the zenphoto.org WEB pages: http://www.zenphoto.org/documentation/

    There you will see all the functons that might be of use to you.

    What HTML issues are you having? `getSizedImage` should produce a valid reference.
Sign In or Register to comment.