views:

51

answers:

2

I have a bunch of images that I need others to browse via a web browser in pretty much the same way as Apache-Gallery.

I'd be able to dump all my images in a directory so that users hitting:

http://server:port/directory

would see small thumbnails and selecting an image would load it full size on a page with options to browse the previous or next image.

I'm looking for a non Apache solution, much like the wonderfull Python simple http server, that can be launched anywhere with minimal configuration & fuss e.g.

python -m SimpleHTTPServer 8000

In fact, the python solution above is pretty much want I want except it doesn't thumbnail the images but just a simple directory listing.

Happy to use an app written in any common language so long as it is self contained and can run on linux on a custom port (and to re-iterate, not an Apache module).

UPDATE

I just found a python script called curator which is simple to run. It generates the required thumbs and static html from any images in the directory you point it at, after which you can use the SimpleHttpServer to vend the results.

+1  A: 

Although it doesnt use the SimpleHTTPServer class, this cgi-bin script shows how to display images in a very simply way. Extend it to fit your needs. Source is here.

from os import listdir
from random import choice

ext2conttype = {"jpg": "image/jpeg",
                "jpeg": "image/jpeg",
                "png": "image/png",
                "gif": "image/gif"}

def content_type(filename):
    return ext2conttype[filename[filename.rfind(".")+1:].lower()]

def isimage(filename):
    """true if the filename's extension is in the content-type lookup"""
    filename = filename.lower()
    return filename[filename.rfind(".")+1:] in ext2conttype

def random_file(dir):
    """returns the filename of a randomly chosen image in dir"""
    images = [f for f in listdir(dir) if isimage(f)]
    return choice(images)

if __name__ == "__main__":
    dir = "c:\\python\\random_img\\"
    r = random_file(dir)
    print "Content-type: %s\n" % (content_type(r))
    print file(dir+r, "rb").read()
mizipzor
thx, will check it out
Joel
A: 

Thanks for the answers and comments. The solution I ended up using was as per my update:

  1. Run curator in the directory containing all my images. This generates thumbs and an index page, as well as pagination to all the full sized images.
  2. Run "*python -m SimpleHTTPServer 8000*" in that directory to browse the resultant html generated by curator

So this is a simple two step process that pretty much satisfies my initial requirements.

Joel