コード例 #1
0
def jpg2png(path):
    imlist = ut.get_imlist(path, ".jpg")
    print imlist
    for i in imlist:
        fname = os.path.splitext(i)[0] + ".png"
        try:
            Image.open(i).save(fname)
        except:
            print "Cannot convert file " + i
        else:
            print i + " converted"
コード例 #2
0
def add_watermarks(path, logopath, logo_size=[200, 100], position=[0, 0]):
    imlist = ut.get_imlist(path, ".jpg")
    for i in imlist:
        fname = os.path.splitext(i)[0] + '_w.jpg'
        im = Image.open(i).convert('RGBA')
        logo = Image.open(logopath).convert('RGBA')
        try:
            out = add_watermark_single(im, logo, logo_size, position)
            out.convert('RGB').save(fname)
        except Exception as e:
            print "Cannot convert file.Error info: {0}".format(i), e
        else:
            print "{0} coverted".format(i)
コード例 #3
0
def add_watermarks(path, content = 'Python', position = [0, 0], color = [255,255,255,100], fpath = "LucidaTypewriterRegular.ttf"):
    # Get image list of specified directory
    imlist = ut.get_imlist(path, ".jpg")
    for i in imlist:
        fname = os.path.splitext(i)[0] + '_w.jpg'
        im = Image.open(i).convert('RGBA')
        try: 
            out = add_watermark_single(im, content, position, color, fpath)
            #out is RGBA after alpha composite with watermark
            out.convert("RGB").save(fname)
        except Exception as e:
            print "Cannot add water mark to {0}, due to error(s): {1}".format(i, e)
        else:
            print "Water mark added to {1}".format(i)
コード例 #4
0
def thumbnail(path, size=(128, 128)):
    imlist = ut.get_imlist(path, ".jpg")
    for i in imlist:
        fname = os.path.splitext(i)[0] + "_s.jpg"
        print fname
        try:
            im = Image.open(i)
            im.thumbnail(size)
            im.save(fname)
        except Exception as e:
            print "Cannot create thumbnail of file {0} due to error(s): {1}".format(
                i, e)
        else:
            print "Thumbnail of {0} created".format(i)