1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] PIL Image.resize() not resizing the picture

Discussão em 'Python' iniciado por Stack, Setembro 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have some strange problem with PIL not resizing the image.

    from PIL import Image
    img = Image.open('foo.jpg')

    width, height = img.size
    ratio = floor(height / width)
    newheight = ratio * 150

    img.resize((150, newheight), Image.ANTIALIAS)

    img.save('mugshotv2.jpg', format='JPEG')


    This code runs without any errors and produces me image named mugshotv2.jpg in correct folder, but it does not resize it. It does something to it, because the size of the picture drops from 120 kb to 20 kb, but the dimensions remain the same.

    Perhaps you can also suggest way to crop images into squares with less code. I kinda thought that Image.thumbnail does it, but what it did was that it scaled my image to 150 px by its width, leaving height 100px.

    Continue reading...

Compartilhe esta Página