Cropping an image with Python Pillow

后端 未结 1 981
迷失自我
迷失自我 2020-12-13 18:28

I installed Python Pillow and am trying to crop an image.

Other effects work great (for example, thumbnail, blurring image, etc.)

Whenever I run the code bel

相关标签:
1条回答
  • 2020-12-13 18:53

    The problem is with logic, not Pillow. Pillow is nearly 100% PIL compatible. You created an image of 0 * 0 (left = right & top = bottom) size. No display can show that. My code is as follows

    from PIL import Image
    
    test_image = "Fedora_19_with_GNOME.jpg"
    original = Image.open(test_image)
    original.show()
    
    width, height = original.size   # Get dimensions
    left = width/4
    top = height/4
    right = 3 * width/4
    bottom = 3 * height/4
    cropped_example = original.crop((left, top, right, bottom))
    
    cropped_example.show()
    

    Most probably this is not what you want. But this should guide you towards a clear idea of what should be done.

    0 讨论(0)
提交回复
热议问题