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 ImageWindows: 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-pip4
- 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-pip1 sudo apt-get update sudo apt-get install python-pip2
Lấ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 Image2open from PIL import Image4
sudo apt-get update sudo apt-get install python-pip5 sudo apt-get update sudo apt-get install python-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8
sudo apt-get update sudo apt-get install python-pip9= from PIL import Image1
- from PIL import Image6__ from PIL import Image8To 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-pip1 sudo apt-get update sudo apt-get install python-pip2
Lấ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.
trytry7
sudo apt-get update sudo apt-get install python-pip5 sudo apt-get update sudo apt-get install python-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8
sudo apt-get update sudo apt-get install python-pip9= from PIL import Image1
try8 3 4 5
from PIL import Image6__ from PIL import Image8
try8sudo apt-get update sudo apt-get install python-pip4
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.
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-pip1 sudo apt-get update sudo apt-get install python-pip2
Lấ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.
trytry7
sudo apt-get update sudo apt-get install python-pip5 sudo apt-get update sudo apt-get install python-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8
sudo apt-get update sudo apt-get install python-pip9= from PIL import Image1
from PIL import Image6__ from PIL import Image8
Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
try8 3sudo apt-get update sudo apt-get install python-pip10: 5
from PIL import Image6__ from PIL import Image8
try8sudo apt-get update sudo apt-get install python-pip4
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. Image.resize(size)- Here size is provided as a
2-tuple width and height.
sudo apt-get update sudo apt-get install python-pip1 sudo apt-get update sudo apt-get install python-pip2
Lấ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.
trytry7
sudo apt-get update sudo apt-get install python-pip5 sudo apt-get update sudo apt-get install python-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8
sudo apt-get update sudo apt-get install python-pip9= from PIL import Image1
from PIL import Image6__ from PIL import Image8
try8 3sudo apt-get update sudo apt-get install python-pip58: 5
from PIL import Image6__ from PIL import Image8
try8sudo apt-get update sudo apt-get install python-pip4
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. 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-pip1 sudo apt-get update sudo apt-get install python-pip2
Lấ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.
trytry7
sudo apt-get update sudo apt-get install python-pip5 sudo apt-get update sudo apt-get install python-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8
sudo apt-get update sudo apt-get install python-pip9= from PIL import Image1
try8sudo apt-get update sudo apt-get install python-pip99 from PIL import Image00open5 from PIL import Image00sudo apt-get update sudo apt-get install python-pip55
try8 3 from PIL import Image06 5
from PIL import Image6__ from PIL import Image8
Mộ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 Imagetry3 try4
trytry7
try8try9=
try8 from PIL import Image35 from PIL import Image36
sudo apt-get update sudo apt-get install python-pip1 sudo apt-get update sudo apt-get install python-pip2
try8sudo apt-get update sudo apt-get install python-pip4
img 1 img 2______7 img 5try7
img 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-pip5 sudo apt-get update sudo apt-get install python-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8
try3 try4
trytry7
try8try9=
try8 from PIL import Image35 from PIL import Image36
try8 from PIL import Image73 from PIL import Image74 5
sudo apt-get update sudo apt-get install python-pip1 sudo apt-get update sudo apt-get install python-pip2
try8sudo apt-get update sudo apt-get install python-pip4
img 1 img 2______7 img 5try7
img 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-pip5 sudo apt-get update sudo apt-get install python-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8
try3 try4
trytry7
try8try9=
try8 from PIL import Image35 from PIL import Image36
sudo apt-get update sudo apt-get install python-pip1 sudo apt-get update sudo apt-get install python-pip2
try8sudo apt-get update sudo apt-get install python-pip4
img 1 img 2______7 img 5try7
img 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 Imagetry3 try4
trytry7
try8try9=
try8 from PIL import Image35 from PIL import Image36
sudo apt-get update sudo apt-get install python-pip1 sudo apt-get update sudo apt-get install python-pip2
img 1 img 2______7 img 5try7
sudo apt-get update sudo apt-get install python-pip1 sudo apt-get update sudo apt-get install python-pip2
try8sudo apt-get update sudo apt-get install python-pip4
img 1 img 2______7 img 5try7
img 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 Imagetry3 try4
sudo apt-get update sudo apt-get install python-pip5 sudo apt-get update sudo apt-get install python-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8
try8try9=
try8try72try73open5try73try76
try8 3try79 5
sudo apt-get update sudo apt-get install python-pip1 sudo apt-get update sudo apt-get install python-pip2
try8sudo apt-get update sudo apt-get install python-pip4
img 1 img 2______7 img 5try7
img 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-pip6sudo apt-get update sudo apt-get install python-pip7 sudo apt-get update sudo apt-get install python-pip8