PIL és la biblioteca d'imatges de Python que proporciona a l'intèrpret de Python capacitats d'edició d'imatges. El mòdul Imatge proporciona una classe amb el mateix nom que s'utilitza per representar una imatge PIL. El mòdul també proporciona una sèrie de funcions de fàbrica, incloses funcions per carregar imatges dels fitxers i per crear imatges noves.
Image.resize() Retorna una còpia redimensionada d'aquesta imatge.
Sintaxi: Image.resize(mida, resample=0)
Paràmetres :
mida – La mida sol·licitada en píxels, com a 2-tuple: (amplada, alçada).
tornar a mostrejar – Un filtre de mostreig opcional. Pot ser PIL.Image.NEAREST (utilitza el veí més proper), PIL.Image.BILINEAR (interpolació lineal), PIL.Image.BICUBIC (interpolació spline cúbica) o PIL.Image.LANCZOS (un filtre de baixada de mostreig d'alta qualitat). ). Si s'omet, o si la imatge té el mode 1 o P, s'estableix PIL.Image.NEAREST. En cas contrari, el filtre predeterminat és Resampling.BICUBIC.
Tipus de retorns : Un objecte Image.
Imatge utilitzada:

Python 3
# Importing Image class from PIL module> from> PIL>import> Image> # Opens a image in RGB mode> im>=> Image.>open>(r>'C:UsersSystem-PcDesktopybear.webp'>)> # Size of the image in pixels (size of original image)> # (This is not mandatory)> width, height>=> im.size> # Setting the points for cropped image> left>=> 4> top>=> height>/> 5> right>=> 154> bottom>=> 3> *> height>/> 5> # Cropped image of above dimension> # (It will not change original image)> im1>=> im.crop((left, top, right, bottom))> newsize>=> (>300>,>300>)> im1>=> im1.resize(newsize)> # Shows the image in image viewer> im1.show()> |
>
>
Sortida:

Un altre exemple: Aquí fem servir el valor diferent de mida de la notícia.
Python 3
# Importing Image class from PIL module> from> PIL>import> Image> # Opens a image in RGB mode> im>=> Image.>open>(r>'C:UsersSystem-PcDesktopybear.webp'>)> # Size of the image in pixels (size of original image)> # (This is not mandatory)> width, height>=> im.size> # Setting the points for cropped image> left>=> 6> top>=> height>/> 4> right>=> 174> bottom>=> 3> *> height>/> 4> # Cropped image of above dimension> # (It will not change original image)> im1>=> im.crop((left, top, right, bottom))> newsize>=> (>200>,>200>)> im1>=> im1.resize(newsize)> # Shows the image in image viewer> im1.show()> |
>
números romans 1-100
>
Sortida:
