logo

Pitón PIL | Método Image.resize()

PIL es la biblioteca de imágenes de Python que proporciona al intérprete de Python capacidades de edición de imágenes. El módulo Imagen proporciona una clase con el mismo nombre que se utiliza para representar una imagen PIL. El módulo también proporciona una serie de funciones de fábrica, incluidas funciones para cargar imágenes desde archivos y crear nuevas imágenes.
Imagen.redimensionar() Devuelve una copia redimensionada de esta imagen.

Sintaxis: Image.resize(tamaño, remuestreo=0)
Parámetros :
tamaño – El tamaño solicitado en píxeles, como una tupla de 2: (ancho, alto).
remuestrear – Un filtro de remuestreo opcional. Puede ser uno de PIL.Image.NEAREST (use el vecino más cercano), PIL.Image.BILINEAR (interpolación lineal), PIL.Image.BICUBIC (interpolación spline cúbica) o PIL.Image.LANCZOS (un filtro de reducción de resolución de alta calidad). ). Si se omite, o si la imagen tiene el modo 1 o P, se establece PIL.Image.NEAREST. De lo contrario, el filtro predeterminado es Resampling.BICUBIC.
Tipo de devolución : Un objeto de imagen.



Fuente

Imagen utilizada:



Python3






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

>

>

Producción:

Otro ejemplo: Aquí utilizamos diferentes valores de tamaño de noticia.

Python3




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

>

>

Producción:

mapa java