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