python-pillow image processing module

from the PIL Import ImageColor 
ImageColor.getcolor ( ' Red ' , ' the RGB ' ) # Color Mode
ImageColor.getcolor ( ' Red ' , ' the RGBA ' ) # Color transparency schema
# Switch to a picture directory 
% cd IMAGE
from the PIL Import Image 
IM = Image.open ( ' ludashi.jpg ' ) # thumbnail image file produced a note to open the path when the 
Print (im.format, im.size, im.mode) # format, size, color mode,
JPEG (900, 600) RGB
W, H = im.size # obtain an image size of width and height, respectively 
Print ( ' size: SX% S% ' % (W, H))
im.thumbnail ((W 2 //, H // 2)) # scaled% 50 
Print ( ' resize the image: SX% S% ' % (W 2 //, H // 2))
im.save ( ' ludashi-50.jpg ' , ' jpeg ' ) # image is saved as a jpeg format
im.show () # show pictures
im_size = im.resize((w//4,h//4)) #调整大小
im_size.save('ludashi-25.jpg')
from the PIL Import The ImageEnhance # enhance contrast 
ENH = ImageEnhance.Contrast (IM) 
enh.enhance ( 1.3) the .Show ( " 30% contrast enhancement " )
# Cropped image 
Box = (100,100,400,400 ) 
Region = im.crop (Box) 
region.save ( " ludashi-c.jpe " )
# Cropped image 
Box = (100,100,400,400 ) 
Region = im.crop (Box) 
region.save ( " ludashi-c.jpe " )
# 旋转图像 
im.rotate (90) .Sava ( ' ludas-90.jpg ' ) 
im.rotate ( 180) .Sava ( ' mad-180.jpg ' ) 
im.rotate ( 8) .Sava ( ' mad-9 .jpg ' )
# Mirror inversion 
im.transpose (Image.FLIP_LEFT_RIGHT) .save ( ' luda- horizontal flip .jpg ' ) 
im.transpose (Image.FLIP_TOP_BOTTOM) .save ( ' flipped vertical luda- .jpg ' )
# Add watermarks, 

# Open logo file 
logo_file = ' logo.png ' 
im_logo = Image.open (logo_file) # open the file 
logo_w, logo_h = im_logo.size   # get the logo size 

# open the target file 
target = ' ludashi.jpg ' 
im_target = Image.open (target) 
target_w, target_h = im_target.size   # need watermarked file size 

# watermarked 
im_copy = im_target.copy ()   # make a copy 
im_copy.paste (im_logo, (target_w-logo_w , target_h-logo_h), im_logo) # start position (coordinates) 
im_copy.save ( 'Logo.Jpg-Luda ' ) # save
# View band and color values of each pixel 
im.getbands ()
im.getpixel ((111,1))   # pixel coordinates
# New pictures fill text 
from PIL Import ImageDraw, ImageFont 
im_new = Image.new ( ' RGBA ' , (400, 400), ' White ' ) # color mode, size, background 
PIC = ImageDraw.Draw (im_new) 
pic.text (( 50,50), ' uge3 ' , Fill = ' Red ' ) # coordinates, contents, text color 
im_new.save ( ' uge3.png ' )
# New image, fill in the text, font handling 
Import os
 from PIL Import ImageDraw, ImageFont
 # fonts_path = R'C: \ Windows \ Fonts' Fonts directory #windows system 
fonts_path r = ' / usr / report this content share / Fonts / dejavu '   # Linux the 
font = ImageFont.truetype (the os.path.join (fonts_path, ' YuGothB.ttc ' )) 
im_new = Image.new ( ' the RGBA ' , (500,500), ' White ' ) 
PIC = ImageDraw.Draw (im_new) 
PIC. text (( 50, 50), ' Indi Home Arts mountain ' , the Fill = 'Black ' , font = font) # coordinates, contents, colors, font 
im_new.save ( ' uge3-font-1.png ' )

 

Guess you like

Origin www.cnblogs.com/uge3/p/11244491.html