Resize Pil image


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. def resize(im,percent):
  2. """ retaille suivant un pourcentage 'percent' """
  3. w,h = im.size
  4. return im.resize(((percent*w)/100,(percent*h)/100))
  5.  
  6. def resize2(im,pixels):
  7. """ retaille le coté le plus long en 'pixels'
  8. (pour tenir dans une frame de pixels x pixels)
  9. """
  10. (wx,wy) = im.size
  11. rx=1.0*wx/pixels
  12. ry=1.0*wy/pixels
  13. if rx>ry:
  14. rr=rx
  15. else:
  16. rr=ry
  17.  
  18. return im.resize((int(wx/rr), int(wy/rr)))

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.