Search code examples
pythonpython-imaging-library

Pillow rotate not quite right


It is hard to explain so please look at the image. It appears to rotate the data within the image but not the image itself.

original:

enter image description here

Rotated -90:

enter image description here

    block = scene.read_block()
    image = PILImage.fromarray(block)
    image_rotate = image.rotate(-90)
    buf = BytesIO()
    image_rotate.save(buf, "JPEG", quality=90)        
    return buf.getvalue()  

The viewport didn't rotate only the image inside.

Thanks


Solution

  • you need to use expand=True to change the size

    image.rotate(-90, expand=True)
    

    it is in the documentation