The 'Name: ' field must be less than length 100

This commit is contained in:
Hugo 2020-02-17 00:57:58 +02:00
parent eb2d6560a4
commit 85e06057e2

View File

@ -347,7 +347,11 @@ def _save(im, fp, filename):
fp.write(("Image type: %s image\r\n" % image_type).encode("ascii"))
if filename:
fp.write(("Name: %s\r\n" % filename).encode("ascii"))
# Each line must be under length 100, or: SyntaxError("not an IM file")
name_format = "Name: %s\r\n"
max = 100 - len(name_format % "")
# Keep the last part of the string, will hold the filename.ext
fp.write((name_format % filename[-max:]).encode("ascii"))
fp.write(("Image size (x*y): %d*%d\r\n" % im.size).encode("ascii"))
fp.write(("File size (no of images): %d\r\n" % frames).encode("ascii"))
if im.mode in ["P", "PA"]: