📃
Python Reference
  • Installation
  • First Steps
  • Variables
  • Operators and Expressions
  • Control Flow
  • Loops
  • Functions
  • String
  • List
  • Dictionany
  • Modules
  • Class
  • File
  • Folder
  • Module os
  • Image
  • JSON
  • XML
  • Connection MySQL
  • Connection Redis
  • Connection Memcached
  • Connection RabbitMQ
  • Restful client
  • STMP
  • Socket
Powered by GitBook
On this page
  • Cài đặt
  • Mở file
  • Ghi file
  • Tạo thumbnail
  • Các thao tác xử lý hình ảnh
  • Follower me

Was this helpful?

Image

PreviousModule osNextJSON

Last updated 4 years ago

Was this helpful?

Cài đặt

Vào trang web sau để download / cài đặt package PIL cho python của bạn:

Sau khi cài đặt thì có thể sử dụng các module trong package IPL

from PIL import Image

Mở file

Ví dụ:

from PIL import Image
im = Image.open("photo.jpg")

Sau khi mở file hình thành công thì có thể thao tác trên đối tượng im.

Ghi file

Từ đối tượng Image có thể lưu file xuống máy tính bằng phương thức save(path, type).

Ví dụ:

...
im.save('photo_new.jpg', 'JPEG')

Tạo thumbnail

Sử dụng phương thức thumbnail như sau:

Ví dụ:

from PIL import Image
im = Image.open('photo.jpg')
im.thumbnail((100, 100))
im.save('photo_thumbnail.jpg', 'JPEG')

thumbnail không trả về image mới mà thực hiện trên object image đang gọi.

Các thao tác xử lý hình ảnh

Follower me

Tham khảo thêm thư viện PIL tại:

Facebook:

Blog:

Github:

http://pillow.readthedocs.org/en/latest/installation.html
http://pillow.readthedocs.org/en/latest/index.html
https://www.facebook.com/lamsaodecode
https://lamsaodecode.blogspot.com
https://lamsaodecode.github.io/introduction