diff --git a/src/PIL/ImImagePlugin.py b/src/PIL/ImImagePlugin.py index 12c9237f0..fe67b3076 100644 --- a/src/PIL/ImImagePlugin.py +++ b/src/PIL/ImImagePlugin.py @@ -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"]: