Why does PIL thumbnail not resizing correctly?

前端 未结 2 1082
广开言路
广开言路 2021-02-09 16:14

I am trying to create and save a thumbnail image when saving the original user image in the userProfile model in my project, below is my code:

def s         


        
2条回答
  •  忘掉有多难
    2021-02-09 16:29

    The image.thumbnail() function will maintain the aspect ratio of the original image.

    Use image.resize() instead.

    UPDATE

    image = image.resize(THUMB_SIZE, Image.ANTIALIAS)        
    thumb_fn = fn + '-thumb' + ext
    tf = NamedTemporaryFile()
    image.save(tf.name, 'JPEG')
    

提交回复
热议问题