diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index a8461f753..443d4db12 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -324,7 +324,7 @@ def _save_netpbm(im, fp, filename): # -------------------------------------------------------------------- # GIF utilities -def getheader(im, palette, info=None): +def getheader(im, palette=None, info=None): """Return a list of strings representing a GIF header""" optimize = info and info.get("optimize", 0) @@ -352,7 +352,7 @@ def getheader(im, palette, info=None): # global palette if im.mode == "P": # colour palette - if palette is not None and Image.isBytesType(palette): + if palette is not None and isinstance(palette, bytes): paletteBytes = palette else: paletteBytes =im.im.getpalette("RGB")[:maxcolor*3] diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index 688c33a1d..3b60c0d05 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -226,9 +226,8 @@ class ImageFile(Image.Image): self.fp = None # might be shared - if not LOAD_TRUNCATED_IMAGES and not self.map and e < 0: - # Note: If loading a truncated image results in an all black Image, - # the decoder wasn't able to decode anything. + if (t == 0 or not LOAD_TRUNCATED_IMAGES) and not self.map and e < 0: + # still raised if decoder fails to return anything raise_ioerror(e) # post processing diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index 3416711a4..decf04657 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -465,7 +465,7 @@ def _save(im, fp, filename): dpi[0], dpi[1], subsampling, extra, - info.get("exif", "") + info.get("exif", b"") ) ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)]) diff --git a/encode.c b/encode.c index 4f5902e5b..f355f99d0 100644 --- a/encode.c +++ b/encode.c @@ -525,7 +525,7 @@ PyImaging_JpegEncoderNew(PyObject* self, PyObject* args) char* rawExif = NULL; int rawExifLen = 0; - if (!PyArg_ParseTuple(args, "ss|iiiiiiii"PY_ARG_BYTES_LENGTH, + if (!PyArg_ParseTuple(args, "ss|iiiiiiii"PY_ARG_BYTES_LENGTH""PY_ARG_BYTES_LENGTH, &mode, &rawmode, &quality, &progressive, &smooth, &optimize, &streamtype, &xdpi, &ydpi, &subsampling, &extra, &extra_size, diff --git a/py3.h b/py3.h index bee457e06..85979c81c 100644 --- a/py3.h +++ b/py3.h @@ -11,7 +11,7 @@ */ #if PY_VERSION_HEX >= 0x03000000 -#define PY_ARG_BYTES_LENGTH "y#y#" +#define PY_ARG_BYTES_LENGTH "y#" /* Map PyInt -> PyLong */ #define PyInt_AsLong PyLong_AsLong @@ -20,7 +20,7 @@ #define PyInt_AS_LONG PyLong_AS_LONG #else /* PY_VERSION_HEX < 0x03000000 */ -#define PY_ARG_BYTES_LENGTH "s#s#" +#define PY_ARG_BYTES_LENGTH "s#" #if !defined(KEEP_PY_UNICODE) /* Map PyUnicode -> PyString */