python 이미지 처리 인터페이스

#http://pillow.readthedocs.org/en/latest/index.html
#      
# #coding:utf-8
# import os, sys
# from PIL import Image
# sys.argv.append("    ")#    
'''Image  '''
# im = Image.open(sys.argv[1])
# print(im.format,im.size,im.mode)#format    ,size   X ,mode    
# # L  ,RGB  ,CMYK pre-press
#
# size = (32,32)
# im.thumbnail(size)#    
# im.save("/home/zyh/picture/the.jpg")#           jpg
#

'''    '''
# #      jpg  
#
# for infile in sys.argv[1:]:#      ,       
#     f,e = os.path.splitext(infile)#         ;    (fname,fextension)  ,      
#     outfile = f +".jpg"
#     # print e       
#     if infile != outfile:
#         try:
#             Image.open(infile).save(outfile)
#         except IOError:
#             print("can't convert", infile)

# #     
#
# size = (16,16)
# for infile in sys.argv[1:]:
#     outfile = os.path.splitext(infile)[0]+".thumbnail"
#     if infile != outfile:
#         try:
#             im = Image.open(infile)
#             im.thumbnail(size)
#             im.save(outfile,"JPEG")
#         except IOError:
#             print("can't creat thumbnail for",infile)

# #      
# for infile in sys.argv[1:]:
#     try :
#          # with Image.open(infile) as im:#         
#         im = Image.open(infile)
#         print(infile,im.format,"%d x %d"%im.size,im.mode)
#     except IOError:
#         pass

'''      ,  ,    '''
# for infile in sys.argv[1:]:
#     try :
#         im = Image.open(infile)
#         outfile = os.path.splitext(infile)[0]
#
#         #        
#
#         # box = im.copy()#    
#         box = (im.size[0]/3,im.size[1]/3,im.size[0]*2/3,im.size[1]*2/3)#      ,left ,upper,right,lower
#         region = im.crop(box)#         ,
#
#         #    ,     
#
#         region = region.transpose(Image.ROTATE_180)#  180 
#         im.paste(region,box)#   paste(  )   ,   region     ,
#         im.save(outfile+"box.jpeg")
#     except IOError:
#         pass

# #rolling an Image
#
# def roll (image,delta):
#     '''Roll an image sideways'''
#     image = image.copy()
#     xsize,ysize = image.size
#     delta = delta%xsize
#     if delta ==0 : return image
#
#     part1 = image.crop((0,0,delta,ysize))
#     part2 = image.crop((delta,0,xsize,ysize))
#     image.paste(part2,(0,0,xsize-delta,ysize))
#     image.paste(part1,(xsize-delta,0,xsize,ysize))
#
#     return image
#
# for infile in sys.argv[1:]:
#     try :
#         im = Image.open(infile)
#         outfile = os.path.splitext(infile)[0]
#
#         #        
#         roll(im.copy(),300).save(outfile+"roll.jpeg")
#         #im.save(outfile+"box.jpeg")
#     except IOError:
#         pass


    # #      
# for infile in sys.argv[1:]:
#     try :
#         im = Image.open(infile)
#         outfile = os.path.splitext(infile)[0]
#         r,g,b= im.split()#       ,split()      
#         im = Image.merge("RGB",(b,r,g))#  (RGB)   
#         im.save(outfile+"tongdao.jpeg")
#         #im.save(outfile+"box.jpeg")
#     except IOError:
#         pass
#
'''     '''
# for infile in sys.argv[1:]:
#     try :
#         im = Image.open(infile)
#         outfile = os.path.splitext(infile)[0]
#         #       
#
#         out = im.resize((64,64))#     
#         out = im.rotate(30) #        
#         out.save(outfile+"jihe  .jpeg")
#         #    
#         out = im.transpose(Image.FLIP_LEFT_RIGHT) #    
#         out.save(outfile+"jiheLR.jpeg")
#         out = im.transpose(Image.FLIP_TOP_BOTTOM) #    
#         out.save(outfile+"jiheTB.jpeg")
#         out = im.transpose(Image.ROTATE_90) #  90,   rotate  
#         out.save(outfile+"jiheR45.jpeg")
#         out = im.transpose(Image.ROTATE_180)
#         out.save(outfile+"jiheR180.jpeg")
#         out = im.transpose(Image.ROTATE_270)
#
#         out.save(outfile+"jiheR270.jpeg")
#         #im.save(outfile+"box.jpeg")
#     except IOError:
#         pass

'''    '''
#
# for infile in sys.argv[1:]:
#     try :
#         im = Image.open(infile)
#         outfile = os.path.splitext(infile)[0]
#         #       
#         out = im.convert("L")
#         out.save(outfile+"convertL.jpeg")
#     except IOError:
#         pass

'''    ()'''
# for infile in sys.argv[1:]:
#     try :
#         im = Image.open(infile)
#         outfile = os.path.splitext(infile)[0]
#         #       
#
#         from PIL import ImageFilter
#         out = im.filter(ImageFilter.DETAIL)
#         out.save(outfile+"filter.jpeg")
#     except IOError:
#         pass

'''     '''

# for infile in sys.argv[1:]:
#     try :
#         im = Image.open(infile)
#         outfile = os.path.splitext(infile)[0]
#
#         #     
#
#         out = im.point(lambda i: i * 0.3)#     0.3,  point paste             
#         out.save(outfile+"point.jpeg")
#
#         #      
#
#         source = im.split()
#         R,G,B = 0,1,2
#
#         # select regions where red is less than 100
#         mask = source[R].point(lambda i: i<100 and 255)
#         #mask    :  0 ,     ,255   paste    ,     transparency  
#
#         # process the green band
#         out = source[G].point(lambda i: i*10)
#
#         # paste the processed band back, but only where red was < 100
#         source[G].paste(out,None,mask)
#
#         im=Image.merge(im.mode,source)
#         im.save(outfile+"tongdao.jpeg")
#     except IOError:
#         pass

좋은 웹페이지 즐겨찾기