谦虚好学的石榴 · PyQt/QTextEdit/Highlig ...· 1 周前 · |
完美的馒头 · python QTreeWidget ...· 6 天前 · |
高大的卤蛋 · Prevent Cross-Site ...· 6 天前 · |
寂寞的茶叶 · python中linecache如何使用 ...· 2 天前 · |
胆小的香烟 · 如何在Linux服务器上安装Anaconda ...· 2 天前 · |
开心的大海 · A problem moving the ...· 3 月前 · |
气势凌人的拐杖 · Neural Networks (三) ...· 3 月前 · |
聪明伶俐的核桃 · 有关于Go语言的一些tips | ...· 4 月前 · |
朝气蓬勃的圣诞树 · Python写入EXCEL不同sheet的方 ...· 6 月前 · |
魁梧的卤蛋 · linnux 3 - ...· 6 月前 · |
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. It was developed by Fredrik Lundh and several other contributors. Pillow is the friendly PIL fork and an easy to use library developed by Alex Clark and other contributors. We’ll be working with Pillow.
Installation:
pip install Pillow
Installing pip via terminal:
sudo apt-get update sudo apt-get install python-pip
We’ll be working with the Image Module here which provides a class of the same name and provides a lot of functions to work on our images.To import the Image module, our code should begin with the following line:
from PIL import Image
Operations with Images:
#img = Image.open(path)
# On successful execution of this statement,
# an object of Image type is returned and stored in img variable)
try
:
img
=
Image.
open
(path)
except
IOError:
# Use the above statement within try block, as it can
# raise an IOError if file cannot be found,
# or image cannot be opened.
#Image which we want to paste
img2
=
Image.
open
(
"picture2.jpg"
)
img.paste(img2, (
50
,
50
))
#Saved in the same relative location
img.save(
"pasted_picture.jpg"
)
except
IOError:
if
__name__
=
=
"__main__"
:
main()
##An additional argument for an optional image mask image is also available.
If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to [email protected]. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.