Пример #1
0
def main():
    parser = argparse.ArgumentParser(
        description='Image bank creator')
    parser.add_argument('input_image_folder', type=str, 
        help='Folder containing images to insert into new library')
    parser.add_argument('library_name', type=str,
        help='Name of the new image library to create')

    args = parser.parse_args()

    img_dir = path.join(proj_dir, 'Images', args.input_image_folder)
    if not path.isdir(img_dir):
        # error
        print "error:", img_dir, "is not a directory"
        return 1

    img_bank_dir = path.join(proj_dir, 'ImageBanks', args.library_name)
    print img_bank_dir
    imagebank = ImageBank.new(img_bank_dir)

    # add all images from img_dir to image bank
    files = os.listdir(img_dir)
    for f in files:
        f_path = os.path.join(img_dir, f)
        imagebank.add_image_file(f_path)
        print "Added %s" % f

    imagebank.save()
    print "Image bank saved."
Пример #2
0
def main():
    img_dir = path.join(proj_dir, 'Images', 'colors')
    img_bank_dir = path.join(proj_dir, 'Test', 'color_bank')
    imagebank = ImageBank.new(img_bank_dir)

    # add all images from img_dir to image bank
    files = os.listdir(img_dir)
    for f in files:
        f_path = os.path.join(img_dir, f)
        imagebank.add_image_file(f_path)
        print "Added %s" % f

    imagebank.save()
    print "Image bank saved."
Пример #3
0
    def test_create(self):

        if path.exists(self.csv_path):
            os.remove(self.csv_path)
            # remove all other files in folder too
            # except ones beginning with a dot (e.g. .gitignore)
            for filename in os.listdir(self.bank_path):
                if not filename.startswith('.'):
                    os.remove(path.join(
                        self.bank_path, filename))  # DELETES A FILE PERMANENTLY

        # Create new empty image bank
        imagebank = ImageBank.new(self.bank_path)

        # The csv file should exist
        self.assertTrue(path.exists(self.csv_path))

        # Creating a new bank in the same location should raise an exception
        self.assertRaises(Exception, ImageBank.new, self.bank_path)

        # Test adding an image
        image_path = path.join(self.image_dir, 'kirk.jpg')
        imagebank.add_image_file(image_path)
        self.assertTrue(len(imagebank.entries) == 1)
        e = imagebank.entries[0]
        print e
        # Adding it again should raise an exception
        self.assertRaises(Exception, imagebank.add_image_file, image_path)

        # Add a duplicate of the image using a different filename
        image = Image.open(image_path)
        imagebank.add_image(image, 'kirk_duplicate.png')
        self.assertTrue(len(imagebank.entries) == 2)
        # self.assertTrue( str(imagebank.entries[0])==str(imagebank.entries[1]))
        print imagebank.entries[1]

        imagebank.save()