!pip freeze
# I used my installed modules as the word cloud I executed 'pip' freeze
# then copied the resulting words, minus the version to 'wordcloud.txt'
%%writefile wordcloud.txt
aiml
alabaster
altair
anaconda_client
anaconda_project
appdirs
apptools
argcomplete
arrow
astroid
astropy
attrs
Automat
Babel
backports_abc
backports.functools-lru-cache
backports.shutil-get-terminal-size
backports.ssl-match-hostname
BeautifulSoup
beautifulsoup4
bitarray
blaze
bleach
bokeh
boto
Bottleneck
branca
bs4
cdecimal
certifi
cffi
chardet
ChatterBot
chatterbot-corpus
chest
click
get-mak-eurl
cloudpickle
clyent
colorama
coloredlogs
conda
configobj
configparser
constantly
contextlib2
cov-core
coverage
cryptography
cssselect
cycler
Cython
cytoolz
dask
data
datashape
decorator
dill
dlib
docopt
docutils
dot2tex
e
entrypoints
enum34
et-xmlfile
facemorpher
fastcache
Flask
Flask-Admin
Flask-Cors
Flask-GraphQL
Flask-WTF
flickr-api
flickrapi
folium
funcsigs
functions
functools32
future
futures
gevent
gitter
graphene
graphene
sqlalchemy
graphql-core
graphql-relay
graphviz
greenlet
grin
h5py
HeapDict
html2text
html5lib
httplib2
humanfriendly
hyperlink
icrawler
idna
ijson
imageio
imagesize
imutils
incremental
inflect
ipaddress
ipykernel
ipyleaflet
ipython
ipython-genutils
ipyvolume
ipywidgets
irc
iso8601
isort
itsdangerous
jaraco.classes
jaraco.collections
jaraco.functools
jaraco.itertools
jaraco.logging
jaraco.stream
jaraco.text
jdcal
jedi
Jinja2
JSON-log-formatter
json-tricks
jsondatabase
jsonschema
jupyter-client
jupyter-console
jupyter-contrib-core
jupyter-contrib-nbextensions
jupyter-core
jupyter-highlight-selected-word==0.0.11jupyter-latex-envs
jupyter-nbextensions-configurator
jupyterlab
jupyterlab-launcher
labellio-cli
latex
lazy-object-proxy
leveldb
lightning-python
llvmlite
locket
lxml
mahotas
Markdown
markovbot
markovify
MarkupSafe
matplotlib
metakernel
meteor-ejson
mistune
mock
mongoengine
monotonic
more-itertools
mpld3
mpmath
msnoise
msnoise-tomo
multipledispatch
MySQL-python
nbconvert
nbformat
networkx
nltk
nodebox-opengl
nose
nose-cov
notebook
numba
numexpr
numpy
numpydoc
oauth
oauthlib
obspy
odo
olefile
openpyxl
packaging
pandas
pandocfilters
parsel
partd
pathlib2
patsy
pbr
pep8
pexpect
pickleshare
Pillow
pkginfo
plotly
ply
processing
progressbar
promise
prompt-toolkit
protobuf
psutil
PsychoPy
psycopg2
ptyprocess
py
py3-protobuffers
PyAIML
pyamg
pyasn1
pyasn1-modules
pycairo
pychecker
pycosat
pycparser
pycrypto
pycurl
PyDispatcher
pydot
pyee
pyface
pyflakes
pygame
pyglet
Pygments
PyInstaller
pylint
pymongo
pymorph
pymunk
PyMySQL
PyOpenGL
PyOpenGL-accelerate
pyOpenSSL
pyparsing
pytest
python-coveralls
python-dateutil
python-ddp
python-meteor
python-resize-image
python-twitter
pythreejs
pyttsx
pytz
PyWavelets
PyYAML
pyzmq
QtAwesome
QtPy
queuelib
redis
requests
requests-oauthlib
requests-toolbelt
requirements
rope
scandir
scikit-image
scikit-learn
scipy
Scrapy
seaborn
selectivesearch
service-identity
Shapely
shutilwhich
simplegeneric
singledispatch
six
skulpt-python
snowballstemmer
sockjs-tornado
Sphinx
sphinx-rtd-theme
SQLAlchemy
statsmodels
subprocess32
surrealism
SVGFig
svgwrite
sympy
tables
tempdir
tempora
tensorflow
termenu
terminado
testpath
textblob
times
toolz
tornado
tqdm
traitlets
traits
traitsui
traittypes
tweepy
twine
Twisted
TwitterAPI
typing
unicodecsv
Unidecode
vega
virtualenv
vpnotebook
vpython
vtk
w3lib
Wand
wcwidth
webcolors
webencodings
Werkzeug
widgetsnbextension
wrapt
ws4py
WTForms
wxPython
xerox
xlrd
XlsxWriter
xlwt
zope.interface
#%%writefile twitterpost.py
Overwriting wordcloud.txt
import random
def generate_the_word(infile):
with open(infile) as f:
contents_of_file = f.read()
lines = contents_of_file.splitlines()
line_number = random.randrange(0, len(lines))
return lines[line_number]
wrd = (generate_the_word("wordcloud.txt"))
print wrd
scandir
import random
count = 0
while count< 10:
def generate_the_word(infile):
with open(infile) as f:
contents_of_file = f.read()
lines = contents_of_file.splitlines()
line_number = random.randrange(0, len(lines))
return lines[line_number]
wrd = (generate_the_word("wordcloud.txt"))
count = count+1
print wrd
six subprocess32 traittypes parsel nodebox-opengl pyasn1-modules metakernel QtAwesome toolz leveldb
!ls images
0001twitter.jpg 0004twitter.jpg 0007twitter.jpg 0010twitter.jpg 0002twitter.jpg 0005twitter.jpg 0008twitter.jpg 0003twitter.jpg 0006twitter.jpg 0009twitter.jpg
!showme images/0003twitter.jpg
#%%writefile twitterpost.py
#!/anaconda2/bin/python
import os
import random
import sys
import markovify
import twython
from twython import Twython
import time
#removed keys for privacy reasons
CONSUMER_KEY = 'XXXXXXXXXXXXXXXX'
CONSUMER_SECRET = 'XXXXXXXXXXXXXXXX'
ACCESS_KEY = 'XXXXXXXXXXXXXXXX'
ACCESS_SECRET = 'XXXXXXXXXXXXXXXX'
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET)
"""
#USE THIS TO GENERATE RANDOM TEXT FROM THE POSTING.txt file
f = open("POSTING.txt")
text = f.read()
# Build the model.
text_model = markovify.Text(text)
# Print randomly-generated sentences of no more than 140 characters
#STR = (text_model.make_short_sentence(140))
"""
STR = ("This is the text string that will be posted to twitter #python #hashtagmore")
#PATH = your path and image file
PATH = "images/0003twitter.jpg"
# use below to post a random image froma directory
#photo = open('images/'+file_list[rnd]+'.jpg','rb')
photo = open(PATH,'rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status=STR, media_ids=[response['media_id']])
!ls images/NewFolder/
To get an idea where you text will be printed on the picture
from PIL import Image, ImageDraw, ImageFont
import random
from random import randint
base = Image.open("images/0003twitter.jpg").convert('RGBA')
w, h = base.size
Lw = randint(0,w-50)
Lh = randint(0,h-30)
print "the image size is :", w, h,"the text will be printed at :" ,Lw, Lh
the image size is : 543 543 the text will be printed at : 60 190
from PIL import Image, ImageDraw, ImageFont
import random
from random import randint
# get an image
count = 1
# To use an existing image comment out
# start = Image.new('RGB', base.size, (255,200,255))
# and uncomment the next start variable below
#start = Image.open('images/NewFolder/textback.jpg').convert('RGBA')
#Create a blank image
start = Image.new('RGB', base.size, (255,200,255))
start.save('images/StartBlank.jpg')
Notice what is done. An image existing or blank is opened and saved as
a TEMP.jpg. That TEMP.jpg image that will be cycled and printed on in the loop.
import datetime
filename = datetime.datetime.now().strftime("%Y%m%d%H%M%S.jpg")
print filename
20170818120121.jpg
Do not forget to enter the path to your fonts and use a style you have available
from PIL import Image, ImageDraw, ImageFont
import random
import datetime
from random import randint
# get an image
count = 1
start2 = Image.open('images/StartBlank.jpg').convert('RGBA')
start2.save('images/TEMP.jpg')
while count < 256 :
base = Image.open('images/TEMP.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
#generate a random size for the font
int_n = int(count*.2)
Fsize = randint(15,100-int_n)
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", Fsize)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
def generate_the_word(infile):
with open(infile) as f:
contents_of_file = f.read()
lines = contents_of_file.splitlines()
line_number = random.randrange(0, len(lines))
return lines[line_number]
textin = (generate_the_word("wordcloud.txt"))
# calculate the x,y coordinates of the text
w, h = base.size
Lw = randint(-150,w-50)
Lh = randint(-50,h-30)
#textin = "The TwitterBot Project"
#generate random color and opacity
r = randint(0,256)
g = randint(0,256)
b = randint(0,256)
a = randint(0,count)
d.text((Lw,Lh), textin, font=fnt, fill=(r,g,b,a))
out = Image.alpha_composite(base, txt)
out.save("images/TEMP.jpg", "JPEG")
count=count+1
filename = datetime.datetime.now().strftime("images/%Y%m%d%H%M%S.jpg")
out.save(filename, "JPEG")
print filename
out.show()
# that file was saved in two locations one as images/TEMP.jpg
# another as the Date/time.jpg displayed below
images/20170818120537.jpg
#verify it with the viewer of your choce
!showme images/20170818120537.jpg
NOTICE
uncomment the bottom two lines for a unique filename
otherwise each time this cell is executed it will overwrite the image
from PIL import Image, ImageDraw, ImageFont
import random
from random import randint
# get an image
count = 1
# Start with a prepared background
start = Image.open('images/0003twitter.jpg').convert('RGBA')
#save it as a temporary file to cycle this will place 256 ( count <256: ) words on the picture
start.save('images/textbacktmp.jpg')
while count < 256 :
base = Image.open('images/textbacktmp.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
#generate a random size for the font
int_n = int(count*.2)
Fsize = randint(15,100-int_n)
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", Fsize)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
def generate_the_word(infile):
with open(infile) as f:
contents_of_file = f.read()
lines = contents_of_file.splitlines()
line_number = random.randrange(0, len(lines))
return lines[line_number]
textin = (generate_the_word("wordcloud.txt"))
# calculate the x,y coordinates of the text
w, h = base.size
Lw = randint(-150,w-50)
Lh = randint(-50,h-30)
#textin = "The TwitterBot Project"
#generate random color and opacity
r = randint(0,256)
g = randint(0,256)
b = randint(0,256)
a = randint(0,count)
d.text((Lw,Lh), textin, font=fnt, fill=(r,g,b,a))
out = Image.alpha_composite(base, txt)
#save the image and cycle again until count is satisfied
out.save("images/textbacktmp.jpg", "JPEG")
count=count+1
#base = Image.open('images/NewFolder/lightning01.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', out.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 20)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = out.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
marginx = 125
marginy = 30
x = width - marginx
y = height - marginy
#Now add a signature
textin = "SuperDude"
d.text((x,y), textin, font=fnt, fill=(0,0,0,256))
out = Image.alpha_composite(out, txt)
out.save("images/image_signed.jpg", "JPEG")
out.show()
#uncomment the bottom two lines for a unique filename
#otherwise each time this cell is executed it will overwrite the image
#filename = datetime.datetime.now().strftime("images/%Y%m%d%H%M%S.jpg")
#out.save(filename, "JPEG")
!ls images
0001twitter.jpg 0005twitter.jpg 0009twitter.jpg StartBlank.jpg 0002twitter.jpg 0006twitter.jpg 0010twitter.jpg TEMP.jpg 0003twitter.jpg 0007twitter.jpg 20170818120537.jpg textbacktmp.jpg 0004twitter.jpg 0008twitter.jpg image_signed.jpg
!showme images/0006twitter.jpg
from PIL import Image, ImageDraw, ImageFont
# get an image
base = Image.open('images/0006twitter.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 50)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
x = 90
y = 10
textin = "PYTHON ROCKS"
d.text((x,y), textin, font=fnt, fill=(0,0,0,250))
out2 = Image.alpha_composite(base, txt)
out2.save("images/textback_post001.jpg", "JPEG")
out2.show()
!showme images/textback_post001.jpg
This cell may be run several times to adjust text location and size
The original image is untouched, but the result image is overwritten
from PIL import Image, ImageDraw, ImageFont
# get an image
base = Image.open('images/textback_post001.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 20)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
marginx = 125
marginy = 30
x = width - marginx
y = height - marginy
textin = "SuperDude"
d.text((x,y), textin, font=fnt, fill=(0,0,0,180))
out = Image.alpha_composite(base, txt)
out.save("images/textback_post002.jpg", "JPEG")
out.show()
#%%writefile twitterpost.py
#!/anaconda2/bin/python
import os
import random
import sys
import markovify
sys.path.insert(0, '/home/jack/Desktop/pycode/vpython2')
import twython
from twython import Twython
import random
import time
#removed keys for privacy reasons
CONSUMER_KEY = 'XXXXXXXXXXXXXXXX'
CONSUMER_SECRET = 'XXXXXXXXXXXXXXXX'
ACCESS_KEY = 'XXXXXXXXXXXXXXXX'
ACCESS_SECRET = 'XXXXXXXXXXXXXXXX'
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET)
#path = 'images/NewFolder'
f = open("art.txt")
text = f.read()
# Build the model.
text_model = markovify.Text(text)
# Print randomly-generated sentences of no more than 140 characters
#http://paulbourke.net/fractals/
#STR = (text_model.make_short_sentence(140))
STR = ("#wordcloud from pip freeze -Python is loads of fun #pip #freeze #python #modules #pythonmodules #pythongraphics")
#PATH = "/home/jack/Desktop/deep-dream-generator/notebooks/STUFF/experiment/experiment8.jpg"
PATH = "images/textback_post002.jpg"
# 1 , 2, 3, 12, 5, 15, 8, 6
#photo = open('/home/jack/Desktop/deep-dream-generator/notebooks/images/'+file_list[rnd]+'.jpg','rb')
photo = open(PATH,'rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status=STR, media_ids=[response['media_id']])
--------------------------------------------------------------------------- TwythonAuthError Traceback (most recent call last) <ipython-input-51-4300f84e46e7> in <module>() 31 #photo = open('/home/jack/Desktop/deep-dream-generator/notebooks/images/'+file_list[rnd]+'.jpg','rb') 32 photo = open(PATH,'rb') ---> 33 response = twitter.upload_media(media=photo) 34 twitter.update_status(status=STR, media_ids=[response['media_id']]) /home/jack/Desktop/pycode/vpython2/twython/endpoints.pyc in upload_media(self, **params) 149 return self.get('https://upload.twitter.com/1.1/media/upload.json', params=params) 150 --> 151 return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params) 152 153 def upload_video(self, media, media_type, media_category=None, size=None, check_progress=False): /home/jack/Desktop/pycode/vpython2/twython/api.pyc in post(self, endpoint, params, version) 266 def post(self, endpoint, params=None, version='1.1'): 267 """Shortcut for POST requests via :class:`request`""" --> 268 return self.request(endpoint, 'POST', params=params, version=version) 269 270 def get_lastfunction_header(self, header, default_return_value=None): /home/jack/Desktop/pycode/vpython2/twython/api.pyc in request(self, endpoint, method, params, version) 256 257 content = self._request(url, method=method, params=params, --> 258 api_call=url) 259 260 return content /home/jack/Desktop/pycode/vpython2/twython/api.pyc in _request(self, url, method, params, api_call) 192 error_message, 193 error_code=response.status_code, --> 194 retry_after=response.headers.get('X-Rate-Limit-Reset')) 195 196 try: TwythonAuthError: Twitter API returned a 401 (Unauthorized), Invalid or expired token.
from PIL import Image, ImageDraw, ImageFont
import random
from random import randint
# get an image
title = "Python Stuff"
signature_ = "Jack Northrup"
count = 1
start = Image.open('images/0006twitter.jpg').convert('RGBA')
start.save('images/textbacktmp.jpg')
while count < 256 :
base = Image.open('images/textbacktmp.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
#generate a random size for the font
int_n = int(count*.2)
Fsize = randint(15,100-int_n)
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", Fsize)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
def generate_the_word(infile):
with open(infile) as f:
contents_of_file = f.read()
lines = contents_of_file.splitlines()
line_number = random.randrange(0, len(lines))
return lines[line_number]
textin = (generate_the_word("wordcloud.txt"))
# calculate the x,y coordinates of the text
w, h = base.size
Lw = randint(-150,w-50)
Lh = randint(-50,h-30)
#textin = "The TwitterBot Project"
#generate random color and opacity
r = randint(0,256)
g = randint(0,256)
b = randint(0,256)
a = randint(0,count)
d.text((Lw,Lh), textin, font=fnt, fill=(r,g,b,a))
out = Image.alpha_composite(base, txt)
out.save("images/textbacktmp.jpg", "JPEG")
count=count+1
#base = Image.open('images/NewFolder/lightning01.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', out.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 20)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = out.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
marginx = 225
marginy = 50
x = width - marginx
y = height - marginy
d.text((x,y), signature_, font=fnt, fill=(0,0,0,256))
out = Image.alpha_composite(out, txt)
out.save("images/tmpN.jpg", "JPEG")
# save the image then reopen to put a title
base = Image.open('images/tmpN.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 50)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
x = 90
y = 10
d.text((x,y), title , font=fnt, fill=(0,0,0,250))
out2 = Image.alpha_composite(base, txt)
out2.save("images/textbackP_post003.jpg", "JPEG")
out2.show()
!cp images/0006twitter.jpg images/newback.jpg
from PIL import Image, ImageDraw, ImageFont
import random
from random import randint
# get an image
#title = "Python Stuff"
signature_ = "SuperDude"
count = 1
start = Image.open('images/newback.jpg').convert('RGBA')
start.save('images/textbacktmp.jpg')
while count < 256 :
base = Image.open('images/textbacktmp.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
#generate a random size for the font
int_n = int(count*.2)
Fsize = randint(15,100-int_n)
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", Fsize)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
def generate_the_word(infile):
with open(infile) as f:
contents_of_file = f.read()
lines = contents_of_file.splitlines()
line_number = random.randrange(0, len(lines))
return lines[line_number]
textin = (generate_the_word("wordcloud.txt"))
# calculate the x,y coordinates of the text
w, h = base.size
Lw = randint(-150,w-50)
Lh = randint(-50,h-30)
#textin = "The TwitterBot Project"
#generate random color and opacity
r = randint(0,256)
g = randint(0,256)
b = randint(0,256)
a = randint(0,count)
d.text((Lw,Lh), textin, font=fnt, fill=(r,g,b,a))
out = Image.alpha_composite(base, txt)
out.save("images/textbacktmp.jpg", "JPEG")
count=count+1
#base = Image.open('images/NewFolder/lightning01.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', out.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 20)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = out.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
marginx = 225
marginy = 50
x = width - marginx
y = height - marginy
d.text((x,y), signature_, font=fnt, fill=(0,0,0,256))
out = Image.alpha_composite(out, txt)
out.save("images/tmp.jpg", "JPEG")
# save the image then reopen to put a title
base = Image.open('images/tmp.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 50)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
x = 90
y = 10
#generate a title
title = (generate_the_word("titles.txt"))
d.text((x,y), title , font=fnt, fill=(0,0,0,250))
out2 = Image.alpha_composite(base, txt)
out2.save("images/textbackP_post004.jpg", "JPEG")
out2.show()
%%writefile titles.txt
Python Fun
Python Graphics
Generator
Word Cloud
Graphics
Fun w/Python
Python Stuff
PYTHON !!!
Love`en Python
Creative Python
Graphic Fun
Writing titles.txt
#%%writefile TwittePost.py
#!/anaconda2/bin/python
import os
import random
import sys
import markovify
import twython
from twython import Twython
import time
from PIL import Image, ImageDraw, ImageFont
from random import randint
# get an image
#title = "Python Stuff"
signature_ = "My Python Project"
count = 1
start = Image.open('images/newback.jpg').convert('RGBA')
start.save('images/textbacktmp.jpg')
while count < 256 :
base = Image.open('images/textbacktmp.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
#generate a random size for the font
int_n = int(count*.2)
Fsize = randint(15,100-int_n)
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", Fsize)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
def generate_the_word(infile):
with open(infile) as f:
contents_of_file = f.read()
lines = contents_of_file.splitlines()
line_number = random.randrange(0, len(lines))
return lines[line_number]
textin = (generate_the_word("wordcloud.txt"))
# calculate the x,y coordinates of the text
w, h = base.size
Lw = randint(-150,w-50)
Lh = randint(-50,h-30)
#textin = "The TwitterBot Project"
#generate random color and opacity
r = randint(0,256)
g = randint(0,256)
b = randint(0,256)
a = randint(0,count)
d.text((Lw,Lh), textin, font=fnt, fill=(r,g,b,a))
out = Image.alpha_composite(base, txt)
out.save("images/textbacktmp.jpg", "JPEG")
count=count+1
#base = Image.open('images/NewFolder/lightning01.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', out.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 20)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = out.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
marginx = 225
marginy = 50
x = width - marginx
y = height - marginy
d.text((x,y), signature_, font=fnt, fill=(0,0,0,256))
out = Image.alpha_composite(out, txt)
out.save("images/tmp3.jpg", "JPEG")
# save the image then reopen to put a title
base = Image.open('images/tmp3.jpg').convert('RGBA')
#8 5 4 6 3 2
# make a blank image for the text, initialized to transparent text color
txt = Image.new('RGBA', base.size, (255,255,255,0))
# get a font
fnt = ImageFont.truetype("/home/jack/.fonts/Exo-Black.ttf", 50)
# get a drawing context
d = ImageDraw.Draw(txt)
width, height = base.size
# calculate the x,y coordinates of the text
#marginx = 325
#marginy = 75
x = 90
y = 10
#generate a title
title = (generate_the_word("titles.txt"))
d.text((x,y), title , font=fnt, fill=(0,0,0,250))
out2 = Image.alpha_composite(base, txt)
out2.save("images/TM_POST.jpg", "JPEG")
#removed keys for privacy reasons
CONSUMER_KEY = 'XXXXXXXXXXXXXXXX'
CONSUMER_SECRET = 'XXXXXXXXXXXXXXXX'
ACCESS_KEY = 'XXXXXXXXXXXXXXXX'
ACCESS_SECRET = 'XXXXXXXXXXXXXXXX'
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET)
#path = 'images/NewFolder'
f = open("art.txt")
text = f.read()
# Build the model.
text_model = markovify.Text(text)
# Print randomly-generated sentences of no more than 140 characters
#http://paulbourke.net/fractals/
#STR = (text_model.make_short_sentence(140))
STR = ("#All_in_One - #WordCloud #Create - Added ability to randomly choose an image background #Automated")
#PATH = "/home/jack/Desktop/deep-dream-generator/notebooks/STUFF/experiment/experiment8.jpg"
PATH = "images/TM_POST.jpg"
# 1 , 2, 3, 12, 5, 15, 8, 6
#photo = open('/home/jack/Desktop/deep-dream-generator/notebooks/images/'+file_list[rnd]+'.jpg','rb')
photo = open(PATH,'rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status=STR, media_ids=[response['media_id']])
--------------------------------------------------------------------------- TwythonAuthError Traceback (most recent call last) <ipython-input-60-9c6db2cef446> in <module>() 126 #photo = open('/home/jack/Desktop/deep-dream-generator/notebooks/images/'+file_list[rnd]+'.jpg','rb') 127 photo = open(PATH,'rb') --> 128 response = twitter.upload_media(media=photo) 129 twitter.update_status(status=STR, media_ids=[response['media_id']]) /home/jack/Desktop/pycode/vpython2/twython/endpoints.pyc in upload_media(self, **params) 149 return self.get('https://upload.twitter.com/1.1/media/upload.json', params=params) 150 --> 151 return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params) 152 153 def upload_video(self, media, media_type, media_category=None, size=None, check_progress=False): /home/jack/Desktop/pycode/vpython2/twython/api.pyc in post(self, endpoint, params, version) 266 def post(self, endpoint, params=None, version='1.1'): 267 """Shortcut for POST requests via :class:`request`""" --> 268 return self.request(endpoint, 'POST', params=params, version=version) 269 270 def get_lastfunction_header(self, header, default_return_value=None): /home/jack/Desktop/pycode/vpython2/twython/api.pyc in request(self, endpoint, method, params, version) 256 257 content = self._request(url, method=method, params=params, --> 258 api_call=url) 259 260 return content /home/jack/Desktop/pycode/vpython2/twython/api.pyc in _request(self, url, method, params, api_call) 192 error_message, 193 error_code=response.status_code, --> 194 retry_after=response.headers.get('X-Rate-Limit-Reset')) 195 196 try: TwythonAuthError: Twitter API returned a 401 (Unauthorized), Invalid or expired token.
!showme images/TM_POST.jpg