Advertisement
JPablos

pil-image-thumbnail-method. Simple. Python

Jun 1st, 2022
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Creado con Spyder5
  5.  
  6. Basado en: https://www.geeksforgeeks.org/python-pil-image-thumbnail-method/
  7. """
  8.  
  9. from PIL import Image
  10.  
  11. Original = input('Nombre de la inagen: ')       # /ruta/a/la/imagen.(JPEG, PNG,)
  12. alto = int(input('Ingrese el alto: '))
  13. ancho = int(input('Ingrese el ancho: '))
  14. size = (alto, ancho)
  15. thumb = input('Nombre para el thumbnail: ')     # /ruta/a/la/thumb_imagen.(JPEG, PNG,)
  16.  
  17.  
  18. def tnails():
  19.     """
  20.  
  21.    Size βˆ’ Required size
  22.    Resample βˆ’ Optional resampling filter. It can be one of these
  23.    PIL.Image.NEAREST, PIL.Image.BILINEAR, PIL.Image.BICUBIC, or
  24.    PIL.Image.LANCZOS. If omitted, it defaults to PIL.Image.BICUBIC.
  25.    Returns None.
  26.  
  27.    """
  28.     try:
  29.         image = Image.open(Original)
  30.         image.thumbnail(size)
  31.         image.save(thumb)
  32.         image1 = Image.open(thumb)
  33.         image1.show()
  34.     except IOError:
  35.         pass
  36.  
  37.  
  38. tnails()
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement