logo

Python PIL | Méthode Image.resize()

PIL est la bibliothèque d'imagerie Python qui fournit à l'interpréteur Python des capacités d'édition d'images. Le module Image fournit une classe du même nom qui est utilisée pour représenter une image PIL. Le module fournit également un certain nombre de fonctions d'usine, notamment des fonctions permettant de charger des images à partir de fichiers et de créer de nouvelles images.
Image.resize() Renvoie une copie redimensionnée de cette image.

Syntaxe: Image.resize(taille, rééchantillonner=0)
Paramètres :
taille – La taille demandée en pixels, sous forme de 2-tuple : (largeur, hauteur).
rééchantillonner – Un filtre de rééchantillonnage en option. Il peut s'agir de PIL.Image.NEAREST (utiliser le voisin le plus proche), PIL.Image.BILINEAR (interpolation linéaire), PIL.Image.BICUBIC (interpolation spline cubique) ou PIL.Image.LANCZOS (un filtre de sous-échantillonnage de haute qualité). ). En cas d'omission, ou si l'image est en mode 1 ou P, elle est définie sur PIL.Image.NEAREST. Sinon, le filtre par défaut est Resampling.BICUBIC.
Type de retour : Un objet Image.



Source

Image utilisée :



Python3

sélection trier java






# 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()>

>

>

Sortir:

Un autre exemple: Ici, nous utilisons les différentes valeurs newsize.

Python3




combien de zéros dans 1 milliard
# 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()>

>

>

Sortir: