diff --git a/README.md b/README.md new file mode 100644 index 0000000..500903e --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# 八卦 MISC-300 + +--- + +噫 出题人正在学python图像处理就来点福利吧 + +读入文章 + +对字符进行处理 + +把 symbol 进行替换 绘制 + +生成 example.png + +当福利就直接字频好了,值不值三百分啊。 diff --git a/deal.pyc b/deal.pyc new file mode 100644 index 0000000..6d3b59c Binary files /dev/null and b/deal.pyc differ diff --git a/misc300.py b/misc300.py new file mode 100644 index 0000000..9b3843c --- /dev/null +++ b/misc300.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from PIL import Image +import deal +from numpy import * + +__author__ = "Aklis" + +class Typing(object): + def __init__(self, article, width): + self.save_char = [] + self.article = deal.read_article(article) + self.sa, self.total_length = deal.strip_article(filter(self.article), width) + self.width = width + self.height = self.total_length + for i in range(0, 26): + self.save_char.append(Image.open('./symbol/'+chr(65+i)*2+'.png').resize((80, 80)).crop((0, 0, 80, 80))) + self.dst = self.create() + + def create(self): + dst = Image.new("RGBA", (80 * self.width + 20, 80 * self.height + 20), (255, 255, 255)) + return dst + + def draw(self, sentense="Helloddog", line=0): + for n, c in enumerate(sentense): + #print convert(c) + if convert(c) == None: + continue + current = self.save_char[convert(c)] + self.dst.paste(current, (80 * n + 10, 80 * line + 10, 80 * (n+1) + 10, 80 * line + 80 + 10), mask=current) + # self.dst.paste(current, (80 * n, 80 * line, 80 * (n+1), 80 * line + 80)) + + def show(self): + for i, v in enumerate(self.sa[:]): + try: + self.draw(v, i) + except: + print v, "and ", i + self.dst.show() + + def showart(self): + ''' + debug + :return: + ''' + for i, v in enumerate(self.sa[:]): + print i, "and ", v , ' the v is ', type(v) + +def convert(c): + if c == ' ': + return None + else: + return ord(c.upper())-65 + +def filter(s): + seq = [',', '.', '!', '?', '-', ';', '\n', '`', '\'', '\"'] + for char in seq: + s = s.replace(char, '') + return s + +def main(): + article = "./b.txt" + start = Typing(article, 20) + start.show() + start.dst.save('./example.png') + +if __name__ == '__main__': + main()