PIL は、Python インタープリターに画像編集機能を提供する Python Imaging Library です。 Image モジュールは、PIL イメージを表すために使用される同じ名前のクラスを提供します。このモジュールは、ファイルからイメージをロードしたり、新しいイメージを作成したりする関数など、多数のファクトリー関数も提供します。
Image.resize() この画像のサイズ変更されたコピーを返します。
構文: Image.resize(サイズ、リサンプル=0)
パラメーター :
サイズ – 2 つのタプルとしてのピクセル単位の要求サイズ: (幅、高さ)。
リサンプル – オプションのリサンプリング フィルター。これは、PIL.Image.NEAREST (最近傍を使用)、PIL.Image.BILINEAR (線形補間)、PIL.Image.BICUBIC (3 次スプライン補間)、または PIL.Image.LANCZOS (高品質のダウンサンプリング フィルター) のいずれかになります。 )。省略した場合、または画像がモード 1 または P の場合は、PIL.Image.NEAREST が設定されます。それ以外の場合、デフォルトのフィルターは Resampling.BICUBIC です。
戻り値の型 : 画像オブジェクト。
フリップフロップ
使用した画像:

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()> |
>
>
出力:

もう一つの例: ここでは、異なる newsize 値を使用します。
文字列を文字Javaに変換します
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()> |
>
>
出力:
