我正在尝试制作一个以不同方式组合图像的小型 python 程序,但是当我尝试打开图像时,它会抛出:
png.FormatError: FormatError: PNG file has invalid signature.
这是代码:
from png import Reader, Writer
from sys import argv
from io import StringIO
fileName = argv[1];
directions = ["left", "right", "top", "bottom"]
readers = {
"left": Reader(StringIO(
"\"folder"+fileName+"_left.png\""
)),
"right": Reader(StringIO(
"\"folder"+fileName+"_right.png\""
)),
"top": Reader(StringIO(
"\"folder"+fileName+"_top.png\""
)),
"bottom": Reader(StringIO(
"\"folder"+fileName+"_bottom.png\""
))
}
images = {
"left": list(),
"right": list(),
"top": list(),
"bottom": list()
}
for direction in directions:
reader = readers[direction]
image = images[direction]
tempImage = reader.asRGBA8() # error
我确定文件没有损坏,因为它在所有内容(aseprite、gimp、paint、paint.net 和 krita)中都可以正常打开,还有什么可能导致此错误?