Python PIL | Image.resize() -menetelmä
PIL on Python Imaging Library, joka tarjoaa python-tulkin kuvanmuokkausominaisuudet. Kuvamoduuli tarjoaa samannimisen luokan, jota käytetään edustamaan PIL-kuvaa. Moduuli tarjoaa myös useita tehdastoimintoja, mukaan lukien toiminnot kuvien lataamiseen tiedostoista ja uusien kuvien luomiseen.
Image.resize() Palauttaa tämän kuvan kokoisen kopion.
Syntaksi: Image.resize(koko, resample=0)
Parametrit :
koko – Pyydetty koko pikseleinä, 2-levynä: (leveys, korkeus).
uudelleen näyte – Valinnainen uudelleennäytteenottosuodatin. Tämä voi olla jokin seuraavista: PIL.Image.NEAREST (käytä lähintä naapuria), PIL.Image.BILINEAR (lineaarinen interpolointi), PIL.Image.BICUBIC (cubic spline interpolation) tai PIL.Image.LANCZOS (korkealaatuinen alasnäytteistyssuodatin). ). Jos se jätetään pois tai jos kuvassa on tila 1 tai P, se asetetaan PIL.Image.NEAREST. Muussa tapauksessa oletussuodatin on Resampling.BICUBIC.
Palauttaa tyypin : Kuvaobjekti.
Käytetty kuva:
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()> |
Lähtö:
Toinen esimerkki: Tässä käytämme eri uutiskoon arvoa.
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()> |
Lähtö: