Browse Source

copyright and cli options, rename create_gallery to build

pull/9/merge
Simon 15 years ago
parent
commit
bbc4b04df2
  1. 5
      README
  2. 2
      runtests.py
  3. 17
      sigal.py
  4. 22
      sigal/image.py
  5. 2
      sigal/params.py
  6. 2
      test/sigal.conf

5
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.

2
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]

17
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

22
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),

2
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"

2
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"

Loading…
Cancel
Save