程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The PIL library foundation of Python can be seen at a glance

編輯:Python

python in pil The basics of the library

Image

Basic operation of files , Read create

im = Image.open(“ Memory address ”) # Read images
Sure print(im.size,im.format,im.mode) obtain im Basic information of
about im.size Get two values when you can
eg w,h = im.size
image.new(mode,size,color) # new Create an image ,
image2 = image.crop((x1,y1,x2,y2)) shear image
image3 = image.copy() # Copy image
imgae.show() # display picture
image.save(“ Memory address .jpg”) # Store image

There are many, many classes , You can find something else to see

ImageDraw

Add content to the picture , Line , Words etc.

draw = ImageDraw.Draw(im)
You need to put the image (im) Create as draw, You can think of creating an operation object , The operation content is reflected in the image (im) On


Right now draw To operate , Direct manipulation , Do not return objects


draw.line((x1,y1,x2,y2),fill=“red”,width=20) # The starting point (x1,y1) End (x2,y2) Draw a red 20 Wide line
There are also the following figures
draw.rectangle(): Rectangle drawing
draw.arc():( Ellipse ) Drawing of arcs
draw.chord(): Drawing of strings
draw.pieslice(): Drawing of pie chart
draw.ellipse(): Drawing of ellipses
draw.polygon(): Draw polygon

The main draw.text((x1,y1),“content”,fill=“red”,font=) stay (x1,y1) The content is countent, Color company , The font font The content of , Among them, the glyphs generally need to be defined by themselves , be used ImageFont modular

ImageFont

font = ImageFont.truetype(‘C:/windows/fonts/Arial.ttf’,size=40) # Like this , Then import the above draw.text() Medium “ font= ” in

ImageFilter

Very interesting module , You can do many operations on pictures , Fuzzy , Show the edge of the picture and so on

image = image.filter(ImageFilter.BLUR) # Basic usage BLUR Replaceable
CONTOUR Show the outline ( It is interesting to , You can try )
DETAIL Detail enhancement
EDGE_ENHANCE Edge enhancement
EDGE_ENHANCE_MORE Enhanced version of the previous
EMBOSS Relief effect
FIND_EDGES Image of edge information
SMOOTH Smooth filtering ( Make the brightness of the image smooth and gradual , Reduce the mutation gradient , Improve image quality )
Some of them are not written , Many blogs have


2020/10/8


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved