Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Installation:
- Bàn luận On linux terminal type the following:
pip install Pillow
PIL là thư viện hình ảnh Python cung cấp cho trình thông dịch Python khả năng chỉnh sửa hình ảnh. Nó được phát triển bởi Fredrik Lundh và một số người đóng góp khác. Gối là Fork Fork thân thiện và là một thư viện dễ sử dụng được phát triển bởi Alex Clark và những người đóng góp khác. Chúng tôi sẽ làm việc với Gối.
sudo apt-get update sudo apt-get install python-pip
- Linux: Trên Linux Terminal Loại sau: ________ 0 Download the appropriate Pillow package according to your python version. Make sure to download according to the python version you have.
Cài đặt PIP qua thiết bị đầu cuối:
from PIL import Image
Windows: Tải xuống gói gối thích hợp theo phiên bản Python của bạn. Đảm bảo tải xuống theo phiên bản Python bạn có.
- Chúng tôi sẽ làm việc với mô -đun hình ảnh ở đây cung cấp một lớp cùng tên và cung cấp nhiều chức năng để hoạt động trên hình ảnh của chúng tôi. Để nhập mô -đun hình ảnh, mã của chúng tôi sẽ bắt đầu với dòng sau:
try
:
Hoạt động với hình ảnh:
Mở một hình ảnh cụ thể từ một đường dẫn:
sudo apt-get update sudo apt-get install python-pip
4 img
=
Image.
open
____10: The instances of Image class that are created have many attributes, one of its useful attribute is size.sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
from PIL import Image
2open
from PIL import Image
4sudo apt-get update sudo apt-get install python-pip
5sudo apt-get update sudo apt-get install python-pip
6sudo apt-get update sudo apt-get install python-pip
7sudo apt-get update sudo apt-get install python-pip
8sudo apt-get update sudo apt-get install python-pip
9=
from PIL import Image
1from PIL import Image
6__from PIL import Image
8To save any changes that you have made to the image file, we need to give path as well as image format.- Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC. The image rotation needs angle as parameter to get the image rotated.
sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
try
try
7sudo apt-get update sudo apt-get install python-pip
5sudo apt-get update sudo apt-get install python-pip
6sudo apt-get update sudo apt-get install python-pip
7sudo apt-get update sudo apt-get install python-pip
8sudo apt-get update sudo apt-get install python-pip
9=
from PIL import Image
1try
8from PIL import Image
6__from PIL import Image
8try
8sudo apt-get update sudo apt-get install python-pip
4Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
img
8
Lưu các thay đổi trong hình ảnh: Để lưu bất kỳ thay đổi nào bạn đã thực hiện vào tệp hình ảnh, chúng ta cần đưa ra đường dẫn cũng như định dạng hình ảnh.
As seen in the above code snippet, I have used a relative path where my image is located in the same directory as my python code file, an absolute path can be used as well. - Xoay hình ảnh: Xoay hình ảnh cần góc làm tham số để có hình ảnh được xoay. Image.crop[box] takes a 4-tuple [left, upper, right, lower] pixel coordinate, and returns a
rectangular region from the used image.
sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
try
try
7sudo apt-get update sudo apt-get install python-pip
5sudo apt-get update sudo apt-get install python-pip
6sudo apt-get update sudo apt-get install python-pip
7sudo apt-get update sudo apt-get install python-pip
8sudo apt-get update sudo apt-get install python-pip
9=
from PIL import Image
1from PIL import Image
6__from PIL import Image
8Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
try
8sudo apt-get update sudo apt-get install python-pip
10:
5from PIL import Image
6__from PIL import Image
8try
8sudo apt-get update sudo apt-get install python-pip
4Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
img
8 - Lưu các thay đổi trong hình ảnh: Để lưu bất kỳ thay đổi nào bạn đã thực hiện vào tệp hình ảnh, chúng ta cần đưa ra đường dẫn cũng như định dạng hình ảnh. Image.resize[size]- Here size is provided as a
2-tuple width and height.
sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
try
try
7sudo apt-get update sudo apt-get install python-pip
5sudo apt-get update sudo apt-get install python-pip
6sudo apt-get update sudo apt-get install python-pip
7sudo apt-get update sudo apt-get install python-pip
8sudo apt-get update sudo apt-get install python-pip
9=
from PIL import Image
1from PIL import Image
6__from PIL import Image
8try
8sudo apt-get update sudo apt-get install python-pip
58:
5from PIL import Image
6__from PIL import Image
8try
8sudo apt-get update sudo apt-get install python-pip
4Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
img
8 - Lưu các thay đổi trong hình ảnh: Để lưu bất kỳ thay đổi nào bạn đã thực hiện vào tệp hình ảnh, chúng ta cần đưa ra đường dẫn cũng như định dạng hình ảnh. The second argument can be a 2-tuple [specifying the top left corner], or a 4-tuple [left, upper, right, lower] – in this case the
size of pasted image must match the size of this box region, or None which is equivalent to [0, 0].
sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
try
try
7sudo apt-get update sudo apt-get install python-pip
5sudo apt-get update sudo apt-get install python-pip
6sudo apt-get update sudo apt-get install python-pip
7sudo apt-get update sudo apt-get install python-pip
8sudo apt-get update sudo apt-get install python-pip
9=
from PIL import Image
1try
8sudo apt-get update sudo apt-get install python-pip
99from PIL import Image
00open
5from PIL import Image
00sudo apt-get update sudo apt-get install python-pip
55try
8from PIL import Image
06from PIL import Image
6__from PIL import Image
8Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
img
8 - Lưu các thay đổi trong hình ảnh: Để lưu bất kỳ thay đổi nào bạn đã thực hiện vào tệp hình ảnh, chúng ta cần đưa ra đường dẫn cũng như định dạng hình ảnh. This will return a histogram of the image as a list of
pixel counts, one for each pixel in the image. [A histogram of an image is a graphical representation of the tonal distribution in a digital image. It contains what all the brightness values contained in an image are. It plots the number of pixels for each brightness value. It helps in doing the exposure settings.]
from PIL import Imagetry
3try
4try
try
7try
8try
9=
try
8from PIL import Image
35from PIL import Image
36sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2try
8sudo apt-get update sudo apt-get install python-pip
4img
1img
2______7img
5try
7img
8 - Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnhThis feature gives us the mirror image of an image
sudo apt-get update sudo apt-get install python-pip
5sudo apt-get update sudo apt-get install python-pip
6sudo apt-get update sudo apt-get install python-pip
7sudo apt-get update sudo apt-get install python-pip
8try
3try
4try
try
7try
8try
9=
try
8from PIL import Image
35from PIL import Image
36try
8from PIL import Image
73from PIL import Image
74sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2try
8sudo apt-get update sudo apt-get install python-pip
4img
1img
2______7img
5try
7img
8 - Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnhSplitting an image in RGB mode, creates three new images each containing a copy of the original individual bands.
sudo apt-get update sudo apt-get install python-pip
5sudo apt-get update sudo apt-get install python-pip
6sudo apt-get update sudo apt-get install python-pip
7sudo apt-get update sudo apt-get install python-pip
8try
3try
4try
try
7try
8try
9=
try
8from PIL import Image
35from PIL import Image
36sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2try
8sudo apt-get update sudo apt-get install python-pip
4img
1img
2______7img
5try
7img
8 - Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnh Converting an image to an X11 bitmap [A plain text binary image format]. It returns a string containing an X11 bitmap, it can only be used for mode “1” images, i.e. 1 bit pixel black and white
images.
from PIL import Imagetry
3try
4try
try
7try
8try
9=
try
8from PIL import Image
35from PIL import Image
36sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2img
1img
2______7img
5try
7sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2try
8sudo apt-get update sudo apt-get install python-pip
4img
1img
2______7img
5try
7img
8 - Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnh This method creates a thumbnail of the image that is opened. It does not return a new image object, it makes in-place modification to the currently opened image object itself. If you do not want to change the original image object, create a copy and then apply this method. This method also evaluates the appropriate to maintain the aspect ratio of the image according to the size passed.
from PIL import Imagetry
3try
4sudo apt-get update sudo apt-get install python-pip
5sudo apt-get update sudo apt-get install python-pip
6sudo apt-get update sudo apt-get install python-pip
7sudo apt-get update sudo apt-get install python-pip
8try
8try
9=
try
8try
72try
73open
5try
73try
76try
8try
79sudo apt-get update sudo apt-get install python-pip
1sudo apt-get update sudo apt-get install python-pip
2try
8sudo apt-get update sudo apt-get install python-pip
4img
1img
2______7img
5try
7img
8
Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnhMohit Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
sudo apt-get update sudo apt-get install python-pip5
sudo apt-get update sudo apt-get install python-pip6
sudo apt-get update sudo apt-get install python-pip7
sudo apt-get update sudo apt-get install python-pip8