diff --git a/src/PIL/Image.py b/src/PIL/Image.py index eb561611718..6d786fba2b3 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -784,7 +784,7 @@ def tobytes(self, encoder_name: str = "raw", *args: Any) -> bytes: # unpack data e = _getencoder(self.mode, encoder_name, encoder_args) - e.setimage(self.im) + e.setimage(self.im, (0, 0) + self.size) from . import ImageFile diff --git a/src/encode.c b/src/encode.c index 513309c8d7d..f0f17063794 100644 --- a/src/encode.c +++ b/src/encode.c @@ -232,7 +232,7 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) { x0 = y0 = x1 = y1 = 0; /* FIXME: should publish the ImagingType descriptor */ - if (!PyArg_ParseTuple(args, "O|(nnnn)", &op, &x0, &y0, &x1, &y1)) { + if (!PyArg_ParseTuple(args, "O(nnnn)", &op, &x0, &y0, &x1, &y1)) { return NULL; } im = PyImaging_AsImaging(op); @@ -244,15 +244,10 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) { state = &encoder->state; - if (x0 == 0 && x1 == 0) { - state->xsize = im->xsize; - state->ysize = im->ysize; - } else { - state->xoff = x0; - state->yoff = y0; - state->xsize = x1 - x0; - state->ysize = y1 - y0; - } + state->xoff = x0; + state->yoff = y0; + state->xsize = x1 - x0; + state->ysize = y1 - y0; if (state->xsize <= 0 || state->xsize + state->xoff > im->xsize || state->ysize <= 0 || state->ysize + state->yoff > im->ysize) {