def testFileObject(): imageFilename = "/Users/crifan/dev/tmp/python/resize_image_demo/hot day.png" imageFileObj = open(imageFilename, "rb") outputImageFilename = "/Users/crifan/dev/tmp/python/resize_image_demo/hot day_600x600.png" beforeTime = datetime.datetime.now() resizeImage(imageFileObj, (600, 600), outputImageFile=outputImageFilename) afterTime = datetime.datetime.now() print("procesTime: %s" % (afterTime - beforeTime))
def testFilename(): imageFilename = "/Users/crifan/dev/tmp/python/resize_image_demo/hot day.png" outputImageFilename = "/Users/crifan/dev/tmp/python/resize_image_demo/hot day_300x300.png" print("imageFilename=%s" % imageFilename) beforeTime = datetime.datetime.now() resizeImage(imageFilename, (300, 300), outputImageFile=outputImageFilename) afterTime = datetime.datetime.now() print("procesTime: %s" % (afterTime - beforeTime)) outputImageFilename = "/Users/crifan/dev/tmp/python/resize_image_demo/hot day_800x800.png" beforeTime = datetime.datetime.now() resizeImage(imageFilename, (800, 800), outputImageFile=outputImageFilename) afterTime = datetime.datetime.now() print("procesTime: %s" % (afterTime - beforeTime))
def testBinaryBytes(): imageFilename = "/Users/crifan/dev/tmp/python/resize_image_demo/take tomato.png" imageFileObj = open(imageFilename, "rb") imageBytes = imageFileObj.read() # return binary bytes beforeTime = datetime.datetime.now() resizedImageBytes = resizeImage(imageBytes, (800, 800)) afterTime = datetime.datetime.now() print("procesTime: %s" % (afterTime - beforeTime)) print("len(resizedImageBytes)=%s" % len(resizedImageBytes)) # save to file outputImageFilename = "/Users/crifan/dev/tmp/python/resize_image_demo/hot day_750x750.png" beforeTime = datetime.datetime.now() resizeImage(imageBytes, (750, 750), outputImageFile=outputImageFilename) afterTime = datetime.datetime.now() print("procesTime: %s" % (afterTime - beforeTime)) imageFileObj.close()
def compressImageSize(fileBytes): from crifanMultimedia import resizeImage IMAGE_COMPRESS_SIZE = (600, 600) return resizeImage(fileBytes, IMAGE_COMPRESS_SIZE)