def Waifu2xResize(src, width, height, targetWidth, targetHeight):
resize_factor = 2 ** math.ceil(max(math.log2(targetHeight / height), math.log2(targetWidth / targetWidth)))
logging.debug("w: {} h: {} tw: {} th: {} rf: {}".format(width, height, targetWidth, targetHeight, resize_factor))
tmp = tempfile.mkstemp(suffix=".png", prefix="pmsync_cover_")
try:
subprocess.run(["waifu2x-converter-cpp",
"--scale_ratio", str(resize_factor),
"-m", "scale",
"-i", src,
"-o", tmp[1]],
check=True,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
logging.debug("=== CalledProcessError ===")
logging.debug("cmd: {}".format(e.cmd))
logging.debug("output: {}".format(e.stdout.decode()))
logging.debug("stderr: {}".format(e.stderr.decode()))
logging.debug("=== CalledProcessError ===")
os.remove(tmp[1])
return PILResize(tmp[1], width*resize_factor, height*resize_factor, targetWidth, targetHeight)
评论列表
文章目录