我正在try 制作失真效果,但如果我们使用命令行的"Convert"函数,它要求我们指定要转换的文件的路径,并在最后指定最终图像的名称.我想try 从bytesio或仅仅是bytesarray值生成输入图像
这是我的try ,但不幸的是它没有成功(,它说像错误的参数:-Liquid-Resale
# Distort function using imagemmagick
def distort(image, x=45, y=45):
img = Image.open(BytesIO(image))
w, h = img.size
command = [
"convert",
"pipe:0", # Input from stdin
"-liquid-rescale", f"{x}x{y}%!",
"-resize", f"{w}x{h}!",
"pipe:1", # Output to stdout
]
try:
process = subprocess.Popen(
command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = process.communicate(image)
if process.returncode != 0:
logger.info(f"ImageMagick error: {stderr.decode(encoding="latin-1")}")
return None
return stdout
except Exception:
import traceback
traceback.print_exc()
return None