Hi guys,
I am devoloping with Pillow and (Tkinter,BmpImagePlugin,cStringIO,subprocess,ctype s,re .. n) modules
I am using this way when if this situation show me AttributeError
I solve this code line with try-except -
try:
-
from PIL import *
-
except AttributeError: #module has no attribute ImageN
-
import Image
-
import ImageDraw
-
import ImageFont
-
My orginal code part -
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)
-
-
-
My error, -
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
-
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.
2 9373
It could be many things, including permission problems with the image file. Try the following code ("chairs.png", from Manning's book, is attached for testing). Substitute your file name(s) and see what works and what does not, and then you can hopefully adapt to your program. - import Image, ImageDraw
-
-
image_name="chairs.png"
-
im = Image.open(image_name)
-
draw = ImageDraw.Draw(im)
-
draw.line((0, 0) + im.size, fill=255)
-
draw.line((0, im.size[1], im.size[0], 0), fill=128)
-
-
im.show()
Hello @dwblas,
I tried reference name like to you said to me.
And, I did invalid move, I forget Tkinter module in Image attribute
I changed this from Tkinter import *
And, my project file in some .open functions, I changed to these names.
Thank for interest.
Good works.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: NetKev |
last post by:
I added a function 'warn_Admin' and defined it just before another
function 'process_log'. 'process_log' calls this warn_Admin' function.
However, when it gets called i get the following error...
|
by: Evan |
last post by:
Hi
I have a short script that makes 2 calls to methods in another script
as follows:
import canPlaces as canp
callOne=canp.addMe(3,5)
callTwo=canp.estocStn()
|
by: pythonnewb |
last post by:
I am fairly new to programming but have some very basic Java background. I am just learning python and tried to make a module that would allow me to create a file containing an address book. I was...
|
by: Lalit |
last post by:
Hi
I am very new to web development. I started with Pylons. I am using
http://www.rexx.com/~dkuhlman/pylons_quick_site.html as reference to
create a sample web page using pylons.
I got stuck...
|
by: Netwatcher |
last post by:
im try to activate the tutorial code for wxPython,
it is working properly when i tell it to import * from wxPython.wx
but with an error about the package,
i've done as i was told to change the...
|
by: Geared |
last post by:
Hello I'm new to python (been using it all of 2 weeks) and I'm trying to write a program that compares the result of an equation using two different starting numbers that the user chooses. It also...
|
by: jorgejch |
last post by:
Hello, I've started with python (3) recently. Initialy only for scripting. Now I'm trying the object oriented bit.
I'm getting the following error message
<Atom.Atom object at 0x7f0b09597fd0>...
|
by: Terry Fernandez |
last post by:
Can you help me with the NameError?
def addExample(self, klass, words):
"""
* TODO
* Train your model on an example document with label klass ('pos' or 'neg') and
* words, a...
|
by: dashtons7 |
last post by:
I get the following message when I try to run the below program: builtins.NameError: global name 'gallons' is not defined
def main():
square_feet = float(input("Enter the square feet of the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |