Hi guys,
I am devoloping with Pillow and (Tkinter,BmpIma gePlugin,cStrin gIO,subprocess, ctypes,re .. n) modules
I am using this way when if this situation show me AttributeError
I solve this code line with try-except
My orginal code part
My error,
But I installed Pillow module and I create empty python file in import PIL or Image..N module are working. Its isn't just working on the my_project (o.py)
Than you for interest.
Good works.
I am devoloping with Pillow and (Tkinter,BmpIma gePlugin,cStrin gIO,subprocess, ctypes,re .. n) modules
I am using this way when if this situation show me AttributeError
Code:
from PIL import *
Code:
try: from PIL import * except AttributeError: #module has no attribute ImageN import Image import ImageDraw import ImageFont
Code:
class capsGen(object):
def __init__(self):
pass
def videoGen(self,path):
iv = InputVideoStream()
iv.open(path)
self.videoHead(path)
print self.topDuration
frameDiff = list(enumerate(iv.readframe())) #bmp -> [io][1]
self.totalFrame = frameDiff [-1][0]
#16 imgs
self.genImgs = []
curImg = 0
while True:
if curImg < 16:
self.genImgs.append(randint(1,self.totalFrame))
curImg = curImg + 1
else:
break
try:
src = PIL.Image.open("src.png")
ciz = PIL.ImageDraw.draw(src)
ft = PIL.ImageFont.truetype("arial.ttf",32)
ciz.text((190,15),self.fileName,font=ft) #fileName
src.save("1.png")
#print frameDiff[5][0]
for i in self.genImgs:
imj = PIL.Image.open(StringIO.StringIO(frameDiff[i][1])) #base io -> [capsNo][1]
imj.save("%s.png"%i)
except NameError:
src = Image.open("src.png")
ciz = ImageDraw.draw(src)
ft = ImageFont.truetype("arial.ttf",32)
ciz.text((190,15),self.fileName,font=ft) #fileName
src.save("1.png")
#print frameDiff[5][0]
for i in self.genImgs:
imj = Image.open(StringIO.StringIO(frameDiff[i][1])) #base -> [io][1]
imj.save("%s.png"%i)
Code:
Traceback (most recent call last):
File "o.py", line 275, in (module)
run = capsGen()
File "o.py", line 42, in __init__
self.videoGen() #for developers
File "o.py", line 157, in videoGen
ciz = ImageDraw.draw(src)
NameError: global name 'ImageDraw' is not defined
Than you for interest.
Good works.
Comment