New plugin: randompic.py
Toby Smithe <[email protected]> Fri, 29 May 2009 00:14:31 +0100
| Newsgroups | gmane.comp.web.pyblosxom.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, I developed a very simple plug-in to choose a random image from a pre-configured directory, and save its name in a variable. I thought I'd contribute it as it could be useful to someone else, and it's sad to see "portico" all alone in the "images" section of the plug-in registry. The script is attached, and it is licensed "MIT", with copyright attributed to myself. See the file for more information. Regards, -- Toby Smithe :: http://fulltinreality.com ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp as they present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com _______________________________________________ Pyblosxom-devel mailing list Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
randompic.py
(text/x-python, 1.9 KB)
import os, random from PIL import Image """ randompic.py pyblosxom plugin Chooses random image from directory randompic.py chooses a random image from a directory, storing its path in the variable, $random_image CONFIGURATION In config.py, add: py['randompic_directory'] = "/path/to/directory" LICENCE - MIT Copyright (c) 2009 Toby Smithe <[email protected]> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ __author__ = 'Toby Smithe <[email protected]>' __version__ = '1' __url__ = 'http://fulltinreality.com/blog' def cb_prepare(args): request = args["request"] config = request.getConfiguration() data = request.getData() directory = config["randompic_directory"] images = [] for f in os.listdir(directory): try: im = Image.open(os.path.join(directory, f)) except: im = None if im is not None: images.append(f) count = len(images) if count < 1: return index = random.randint(0, (count-1)) data["random_image"] = images[index]