Gallery3:Modules:randimg - Gallery Codex
Personal tools

Gallery3:Modules:randimg

From Gallery Codex

External Image Block

Display a random image on a external page

Description

This tiny module just provides a small interface to be able to fetch a small block of HTML containing a random image. This forum thread may have more information: http://galleryproject.org/node/93574. Thanks to user danneh3826 on the Gallery 3 forum thread for this module for many enhancements and improvements to code and HTML.

Installation

The source files can be found here:
http://code.nkinka.de/gitweb?p=randimg.git;a=summary

Get the latest version

Or to download a version at a specific commit, click the "snapshot" link to the far right of each commit message at the source URL above.

Alternatively, you can use git to clone it:

$ git clone git://code.nkinka.de/randimg.git

The downloaded file will be a tar-gzipped archive named something similar to randimg-HEAD-873eec3.tar.gz. When you extract it, the resulting directory will also be named like randimg-HEAD-873eec3. It probably makes sense to rename that to simply randimg. Drop that directory into the modules/ subdirectory of your Gallery3 installation, then activate the module: Login -> Admin -> Modules. Check the box next to the module. Click update at the bottom of the page.

To see an example of this module in action visit the following URL. Each time you reload the page a new image should appear:

http://natha.nkinka.de

Usage

You can use any language you want on the external site to fetch the contents of the URL and insert it into your page (e.g. Javascript, Python, PHP, a shell script, etc.). If you are using PHP, then something like the following works fine:

     <?php
         $imglink = file_get_contents("http://EXAMPLE.COM/gallery3/index.php/randimg", "r");
         echo "$imglink";
     ?>

The following optional query parameters are accepted:

  • size: accepted values are:
    • thumb (default if no size is specified)
    • resize
    • fullsize
  • maxsize: if this parameter is set, then both width and height are ignored. You may have a mixture of portrait and landscape images in your gallery, and this setting will apply to the longest dimension. That is, if the image is portrait then this parameter will apply to the height, and for landscape images it will apply to the width. In other words, the longest dimension will not exceed this value.
  • width: a width in pixels which will be applied via CSS.
  • height: a height in pixels which will be applied via CSS.
  • target: the target where the link will be opened.
  • album: the name of the album you would like to limit the random image to. This will not work for subalbums (albums within albums). Thanks to sjesse for suggesting this addition.

Examples:

  • http://EXAMPLE.COM/gallery3/index.php/randimg?size=resize
  • http://EXAMPLE.COM/gallery3/index.php/randimg?size=fullsize&width=600
  • http://EXAMPLE.COM/gallery3/index.php/randimg?size=fullsize&width=640&height=480&target=_blank
  • http://EXAMPLE.COM/gallery3/index.php/randimg?size=fullsize&maxsize=300
  • http://EXAMPLE.COM/gallery3/index.php/randimg?maxsize=300&album=my-awesome-album

Don't forget to edit the URL for the proper location/domain.