Use ImageFile.MAXBLOCK in tobytes() by radarhere · Pull Request #8906 · python-pillow/Pillow

tobytes() sets a buffer size when encoding.

bufsize = max(65536, self.size[0] * 4) # see RawEncode.c

ImageFile also does this when saving an image, but the 65536 value is configurable.

MAXBLOCK = 65536

bufsize = max(MAXBLOCK, bufsize, im.size[0] * 4) # see RawEncode.c

Perhaps we should use ImageFile.MAXBLOCK in tobytes() as well?