action="store_true") args = parser.parse_args() if args.batch: images = imageEdit.openImagesInDir(THISDIR + "/input/*") print(images) for imageRef in images: fileName, image = imageRef fileNameParts = fileName.split("\\") fileName = fileNameParts[len(fileNameParts) - 1] print(fileName) if args.radius is not None: image = imageEdit.roundCorners(image, int(args.radius)) else: image = imageEdit.roundCorners(image, int(image.width / 2)) imageEdit.saveImage(THISDIR + "/output/out-" + fileName, image) else: im = imageEdit.openImage(THISDIR + "/" + args.image) if args.radius is not None: im = imageEdit.roundCorners(im, int(args.radius)) else: im = imageEdit.roundCorners(im, int(im.width / 2)) if args.output is not None: outFileName = args.output else: outFileName = args.image imageEdit.saveImage(THISDIR + "/" + outFileName, im)
def test_reduceColours_optimised(): """ Won't be able to see difference but will be able to .getcolors with maxcolors 256 """ assert(not isinstance(imageEdit.reduceColours(imageEdit.openImage(INPUT + "/test_field.png"), "optimised").getcolors(maxcolors=256), type(None)))
def test_reduceColours_logo(): """ .getcolors with maxcolors 16 """ assert(not isinstance(imageEdit.reduceColours(imageEdit.openImage(INPUT + "/test_field.png"), "logo").getcolors(maxcolors=16), type(None)))
def test_getSortedColours_none(): assert(imageEdit.getSortedColours(imageEdit.openImage(INPUT+ "/test_field.png")) == [(1, (255, 255, 255, 255)), (1, (1, 1, 1, 255))])
def test_openImage_optimised(): assert(isinstance(imageEdit.openImage(INPUT + "/test.png", "optimised"), Image.Image))
def test_openImage(): assert(isinstance(imageEdit.openImage(INPUT + "/test.png"), Image.Image))
def test_uncrop(): ''' Manual Check Desired Output: An 'uncropped' image of a field ''' imageEdit.saveImage(OUTPUT + "/test_uncrop.png", imageEdit.uncrop(imageEdit.openImage(INPUT + "/test_field.png"), 64))
''' import os, sys, inspect from PIL import Image, ImageDraw, ImageFilter, ImageFont from pathlib import Path THISDIR = str(Path(__file__).resolve().parent) sys.path.insert(0, os.path.dirname(THISDIR) + "/lib") import imageEdit from PIL import Image from io import StringIO INPUT = THISDIR + "/test_lib_imageEdit/i" OUTPUT = THISDIR + "/test_lib_imageEdit/o" IMAGE = imageEdit.openImage(INPUT + "/test.png") def test_logPrint_standard(): savedStdout = sys.stdout try: out = StringIO() sys.stdout = out imageEdit.logPrint("test", "standard") output = out.getvalue().strip() assert output == "test" finally: sys.stdout = savedStdout def test_logPrint_success(): savedStdout = sys.stdout