From 6adc98de7e14274d27f687dce6d09a4e90070005 Mon Sep 17 00:00:00 2001 From: iAklis Date: Tue, 8 Dec 2015 21:48:52 +0800 Subject: [PATCH] first commit --- README.md | 15 ++++++++++++ deal.pyc | Bin 0 -> 1080 bytes misc300.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 README.md create mode 100644 deal.pyc create mode 100644 misc300.py 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 0000000000000000000000000000000000000000..6d3b59ce4d0df873de8995ff8648fb20f871591b GIT binary patch literal 1080 zcmbtS-;2{g5S~r?<63hZic-!OIs8Est~n6I2NCNXRt5Xeatehb#AL6{U7Ez~6e_e& zz5m!hK)=~m`|gG8?zgiuv-5pB?yvp!`03Htn6{sT^&N)!j48pdC?gsJI5bw2xO9W9 zLrIO2I^8H5yOcDnu|~R1Nt3P}sy>je(V9r*HpR%_L%Q@gz5&+(d)HZNVg=-G$0=6x z91{~QZP41Gm7=AhDV2myL4#eORWQzB$Y2|xQ3}Hb#6hWqr~17XNA!_hce=+ z4NAEQ|G3B*5k4T<$-Dpx&W)~2V9N~pDNpC$gZI7udGGkkr_t&0%afBJ(NWedf3gR6 zxhsq+PUB2VQX_Op9Vkz=RoVuQrC4F!z_45w0251V!+5P|< zH3Hu&@P{Q z%~EGnLd?V$<4|Z>T@CA!g-vEGcP==}LIh8yJd~*amvSG`hO4yvtEDxFz@!?`vZJ1; zLlw(j3YH?Ql&=6FBG`$Dz)+AZRhBg=kZT1e0h@PJ)j zaEcAt<{HW~4i982_pwaUFLJSoZb?>}brz-h14*{&7Y`ioDwa(c%2^otqNu&FFf5G} yhS8j-MHPm->W25kX%m)5GmS79Zt)P3>dmZ3=9zvgq>a3R=QNyF!`o{$J@p3{Il~wL literal 0 HcmV?d00001 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()