From bbc4b04df253254c661079341534a5c81ae477c8 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 12 Apr 2011 00:48:38 +0200 Subject: [PATCH] copyright and cli options, rename create_gallery to build --- README | 5 ++--- runtests.py | 2 +- sigal.py | 17 +++++++++++------ sigal/image.py | 22 ++++++++++++---------- sigal/params.py | 2 +- test/sigal.conf | 2 +- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/README b/README index b8940fb..f0f6bb8 100644 --- a/README +++ b/README @@ -12,13 +12,12 @@ Dependencies - Python Imaging Library (PIL) - exiv2 (for exif datas) -- ConfigObj on Ubuntu : - > sudo apt-get install python-imaging python-pyexiv2 python-configobj + > sudo apt-get install python-imaging python-pyexiv2 on Fedora : - > yum install python-imaging pyexiv2 python-configobj + > yum install python-imaging pyexiv2 The script should also work on other system (Windows, Mac) but this has not be tested yet. diff --git a/runtests.py b/runtests.py index dada810..7b28df8 100755 --- a/runtests.py +++ b/runtests.py @@ -40,7 +40,7 @@ if __name__ == '__main__': # create gallery gallery = Gallery(params) - filelist = gallery.create_gallery("./test", "./test/output") + filelist = gallery.build("./test", "./test/output") print "images : %s" % filelist[0] print "thumbnails : %s" % filelist[1] diff --git a/sigal.py b/sigal.py index c1de5a6..102a2fb 100755 --- a/sigal.py +++ b/sigal.py @@ -44,8 +44,10 @@ def main(): parser = OptionParser(usage=usage, version="%prog "+version) - # parser.add_option("-c", "--config", dest="config", - # help="specify an alternative config file") + parser.add_option("-c", "--copyright", dest="copyright", + help="copyright message added to the images") + parser.add_option("-r", "--rename", dest="rename", + help="rename files - specify the basename for renaming") (options, args) = parser.parse_args() @@ -60,16 +62,19 @@ def main(): print "Directory %s does not exist." % input_dir sys.exit(1) - if not os.path.isdir(output_dir): - print "Create %s" % output_dir - os.makedirs(output_dir) + # if not os.path.isdir(output_dir): + # print "Create %s" % output_dir + # os.makedirs(output_dir) print ":: Reading parameters ..." params = read_params(input_dir) + if options.copyright: + params.set('sigal', 'copyright', options.copyright) + # create gallery gallery = Gallery(params) - out_filelist = gallery.create_gallery(input_dir, output_dir) + out_filelist = gallery.build(input_dir, output_dir) return 0 diff --git a/sigal/image.py b/sigal/image.py index ded839c..b9f74aa 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -30,7 +30,7 @@ from utils import get_filelist class Gallery: - "Prepare a gallery of images for Piwigo" + "Prepare a gallery of images" def __init__(self, params): self.imsize = self.getsize(params.get('sigal', 'img_size')) @@ -44,7 +44,7 @@ class Gallery: self.jpgquality = params.getint('sigal', 'jpg_quality') self.exif = params.getint('sigal', 'exif') - self.copyright = params.getint('sigal', 'copyright') + self.copyright = params.get('sigal', 'copyright') self.fileExtList = params.get('sigal', 'fileExtList') def getsize(self, string): @@ -53,7 +53,7 @@ class Gallery: size[0], size[1] = size[1], size[0] return tuple(size) - def create_gallery(self, input_dir, output_dir): + def build(self, input_dir, output_dir): "create image gallery" imglist = get_filelist(input_dir, self.fileExtList) print "Found %i images in %s" % (len(imglist), input_dir) @@ -70,8 +70,16 @@ class Gallery: except OSError: pass + if self.copyright: + self.copyright = '\xa9 ' + self.copyright + return self.process_images(imglist) + def add_copyright(self, img): + "add copyright to image" + draw = ImageDraw.Draw(img) + draw.text((5, img.size[1]-15), self.copyright) + def process_images(self, imglist): "prepare images" imglist.sort() @@ -85,10 +93,6 @@ class Gallery: imgname = raw_input('Enter new image name: ') nfill = 2 if (len(imglist)<100) else 3 - if self.copyright: - copyrightmsg = raw_input('Enter copyright message: ') - copyrightmsg = '\xa9 ' + copyrightmsg - # loop on images for f in imglist: filename = os.path.split(f)[1] @@ -130,10 +134,8 @@ class Gallery: im.thumbnail(thumb_size, Image.ANTIALIAS) - # copyright if self.copyright: - draw = ImageDraw.Draw(im2) - draw.text((5, im2.size[1]-15), copyrightmsg) + self.add_copyright(im2) # save im.save(os.path.join(self.thumb_dir, self.thumb_prefix+filename), diff --git a/sigal/params.py b/sigal/params.py index bfb8ea1..2902889 100644 --- a/sigal/params.py +++ b/sigal/params.py @@ -32,7 +32,7 @@ CONFIGDEFAULTS = { 'square_thumb': 1, 'jpg_quality': 90, 'exif': 1, - 'copyright': 0, + 'copyright': '', 'thumb_dir': "thumbnail", 'bigimg_dir': "pwg_high", 'fileExtList': ".jpg,.jpeg,.JPG,.JPEG,.png" diff --git a/test/sigal.conf b/test/sigal.conf index 134a8b1..46aa7f6 100644 --- a/test/sigal.conf +++ b/test/sigal.conf @@ -16,4 +16,4 @@ jpg_quality = 90 # keep exif metadatas in output image exif = 1 # add a copyright text on the image -copyright = 1 +copyright = "the copyright msg"