Skip to content

Instantly share code, notes, and snippets.

@Salada
Last active August 29, 2015 14:17
Show Gist options
  • Save Salada/a43e0407f253db3ab588 to your computer and use it in GitHub Desktop.
Save Salada/a43e0407f253db3ab588 to your computer and use it in GitHub Desktop.
#-*- coding:utf-8 -*-
__author__ = 'saladaqoo'
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import argparse
import textwrap
import sys
from twython import Twython
import random
APP_KEY = ''
APP_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''
PREFIX = [u"혀짧은", u"먹고살기가 힘들어서 오늘도 노가다를 뛰는", u"니가 알고있는것과는 다른", u"경쟁사에 고소 고발을 남발하는", u"합법적인 로맨티스트"]
HUMAN = [u"두목", u"사라다", u"불티나", u"아쥬", u"박보장기"]
GOODS = [u"오징어", u"병뚜껑", u"세수대야", u"변사체", u"보정속옷" ]
SHOUT = [u"아아아앙", u"오직예수!", u"우와아앙", u"뀨뀨꺄꺄", u"어머낫"]
NEWSMENT = [u"과학자도 대통령 될수있어", u"나는 자연인이다", u"AV 출연한적 있다", u"관심받고 싶었다", u"내가 바로 안전 종결자"]
def WriteText(buf, text, xLoc, yLoc, linewidth, fontSize = 20):
ifont = ImageFont.truetype('NanumBarunGothic.ttf', fontSize)
lines = textwrap.wrap(text, width=linewidth)
for line in lines:
print line
width, height = ifont.getsize(line)
buf.text((xLoc, yLoc), line, font=ifont, fill=(0,0,0))
yLoc += height
def main():
prefixSample = random.sample(PREFIX, 3)
shoutSample = random.sample(SHOUT, 1)
goodsSample = random.sample(GOODS, 2)
humanSample = random.sample(HUMAN, 3)
newsSample = random.sample(NEWSMENT, 2)
desc1 = u"아무마리나 " + prefixSample[0] + u" 삼형제다!!!"
desc2 = prefixSample[0]+ u" 삼형제!!!"
desc4 = shoutSample[0] + u" " + goodsSample[0]
desc3 = prefixSample[1] + u" " + humanSample[0]
desc6 = newsSample[0]
desc5 = prefixSample[2] + u" " + humanSample[1]
desc8 = newsSample[1]
desc7 = goodsSample[1] + u" " + humanSample[2]
image = Image.open("brothers_upscaling.png").convert('RGB')
print image.format, image.size, image.mode
#text = 'Sample Text SampleSample sdafas dfsadfds sadfk;waefm sdagkm adlfkm sdf'
text = u'개노asfsa답 삼adfaf형제다! 노asfafadf이다! 답asfadfadf이없다!'
buf = ImageDraw.Draw(image)
# WriteText(buf, text, 266, 29, 10)
# WriteText(buf, text, 274, 317, 10)
# WriteText(buf, text, 893, 640, 10)
# WriteText(buf, text, 683, 625, 10)
# WriteText(buf, text, 531, 635, 10)
# WriteText(buf, text, 345, 633, 10)
# WriteText(buf, text, 165, 628, 10)
# WriteText(buf, text, 5, 629, 10)
WriteText(buf, desc1, 266, 29, 7)
WriteText(buf, desc2, 272, 317, 6)
WriteText(buf, desc3, 893, 640, 5)
WriteText(buf, desc4, 683, 625, 5)
WriteText(buf, desc5, 531, 635, 7)
WriteText(buf, desc6, 345, 633, 5)
WriteText(buf, desc7, 165, 628, 8)
WriteText(buf, desc8, 5, 629, 5)
image.save('sample-out.png', 'PNG')
twitter = Twython(APP_KEY, APP_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
photo = open('sample-out.png', 'rb')
twitter.update_status_with_media(media=photo)
if __name__ == '__main__':
main()
@Salada
Copy link
Author

Salada commented Mar 29, 2015

https://gist.github.com/Salada/a43e0407f253db3ab588#file-gaenodap-py-L19

용법상
buf.text((xLoc, yLoc), line, font=ifont, fill=(0, 0, 0))
으로만 쓰면 끝나는데, 안돌아감 (상황정리 끗)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment