使用python3的ASCII图像过滤器

时间:2017-08-14 00:59:06

标签: python python-3.x

我想使用python3创建一个ASCII图像过滤器,我已经编写了一个将图像转换为字符的代码,但我想让它更像第二张图片。

mycode的:

from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import string
import random

def solid():
    return random.choice('m#UQ=MX@')

def notsolid():
    return  random.choice('1-+;a.O')

im = Image.open('1.png')
pixelMap = im.load()
img = Image.new( im.mode, im.size)
pixelsNew = img.load()
draw = ImageDraw.Draw(im)
font = ImageFont.truetype("ac.TTF", 2)

for i in range(img.size[0]):
    for j in range(img.size[1]):
        if pixelMap[i,j][0] > 0 and pixelMap[i,j][0] <= 150:
            pixelMap[i,j] = (0, 0, 0)
            draw.text((i, j),solid(),(255,255,255),font=font)
        elif pixelMap[i,j][0] > 150 and pixelMap[i,j][0] <= 255:
            pixelMap[i,j] = (255, 255, 255)
            draw.text((i, j),notsolid(),(0,0,0),font=font)

pic1 pic2

0 个答案:

没有答案