PIL ir Python attēlveidošanas bibliotēka, kas nodrošina Python tulkam attēlu rediģēšanas iespējas. Attēla modulis nodrošina klasi ar tādu pašu nosaukumu, ko izmanto, lai attēlotu PIL attēlu. Modulis nodrošina arī vairākas rūpnīcas funkcijas, tostarp funkcijas attēlu ielādei no failiem un jaunu attēlu izveidei.
Image.resize() Atgriež šī attēla kopiju ar mainītu izmēru.
Sintakse: Image.resize(size, resample=0)
Parametri :
Izmērs – Pieprasītais izmērs pikseļos, kā 2 korpuss: (platums, augstums).
atkārtots paraugs – Izvēles atkārtotas paraugu ņemšanas filtrs. Tas var būt viens no PIL.Image.NEAREST (izmantojiet tuvāko kaimiņu), PIL.Image.BILINEAR (lineārā interpolācija), PIL.Image.BICUBIC (kubiskā splaina interpolācija) vai PIL.Image.LANCZOS (augstas kvalitātes lejupiztveršanas filtrs). ). Ja tas ir izlaists vai attēlam ir režīms 1 vai P, tas tiek iestatīts uz PIL.Image.NEAREST. Pretējā gadījumā noklusējuma filtrs ir Resampling.BICUBIC.
Atgriešanas veids : attēla objekts.
Izmantotais attēls:

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()> |
>
>
Izvade:

Vēl viens piemērs: Šeit mēs izmantojam dažādu ziņu lieluma vērtību.
Python3
mantojums 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>=> 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()> |
>
>
Izvade:
