python 기반 그림 문자 변환 코드 인 스 턴 스 구현

코드 사진 을 바로 올 리 면 저희 시원 한 여동생 을 사용 하 세 요.

pil 모듈 이 설치 되 어 있 지 않 으 면 cmd 부터 설치 하 세 요.
입력:pip install pillow

# -*- coding: utf-8 -*-
from PIL import Image

codeLib = '''@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^`'. '''#           
count = len(codeLib)

def transform1(image_file):
  image_file = image_file.convert("L")#       ,  "L"      
  codePic = ''
  for h in range(0,image_file.size[1]): #size          ,'0'     ,'1'   
    for w in range(0,image_file.size[0]):
      gray = image_file.getpixel((w,h)) #         ,               ,            
      codePic = codePic + codeLib[int(((count-1)*gray)/256)]#           
    codePic = codePic+'\r
' return codePic def transform2(image_file): codePic = '' for h in range(0,image_file.size[1]): for w in range(0,image_file.size[0]): g,r,b = image_file.getpixel((w,h)) gray = int(r* 0.299+g* 0.587+b* 0.114) codePic = codePic + codeLib[int(((count-1)*gray)/256)] codePic = codePic+'\r
' return codePic fp = open(r'C:\ \3.jpg','rb') image_file = Image.open(fp) image_file=image_file.resize((int(image_file.size[0]*0.2), int(image_file.size[1]*0.1)))# print (u'Info:',image_file.size[0],' ',image_file.size[1],' ',count) tmp = open('tmp.txt','w') tmp.write(transform1(image_file)) tmp.close() a,b,c=1,2,3 print(a,b,c)
결국 알 아 볼 수 있 을 지 모 르 겠 습 니 다.

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기