failed to run image.py

28 views
Skip to first unread message

74yrs old

unread,
Jan 12, 2010, 9:32:31 AM1/12/10
to indi...@googlegroups.com
Dear Sarkar,
Tried to run the following program - which was copied from your website http://hacking-tesseract.blogspot.com/
    file name: image.py
#!/usr/local/bin/python
 
#-*- coding:utf8 -*-
 
importImagefont,ImageDraw
 
from PIL import Image
 
im = Image.new("RGB",(400,400))
#im.show()
 
draw = ImageDraw.Draw(im)
 
# use a truetype font
font= ImageFont.truetype("/usr/share/fonts/truetype/ttf-bengali-fonts/lohit_bn.ttf",50)
 
txt1="ক"
txt2=" ি"
txt=txt2+txt1
 
draw.text((10, 10), unicode(txt,'UTF-8'), font=font)


When run in terminal of ubuntu9.04 error message displayed as follow:

sriranga@ubuntu:~$ cd Desktop/
sriranga@ubuntu:~/Desktop$ python ./image.py
  File "./image.py", line 6
    import image Font,ImageDraw
                    ^
SyntaxError: invalid syntax
sriranga@ubuntu:~/Desktop$

Request for guidance how to aviod invalid syntax?
With regards,
-sriranga(77yrsold)


sriranga(77yrsold) location: Bangalore

unread,
Jan 29, 2010, 8:54:22 AM1/29/10
to indic-ocr
Dear Deepayan Sarkar,
Awaiting your valuable guidance.
-with regards,
-sriranga(77yrsold)


On Jan 12, 7:32 pm, 74yrs old <withblessi...@gmail.com> wrote:
> Dear Sarkar,
> Tried to run the following program - which was copied from your websitehttp://hacking-tesseract.blogspot.com/

>    * file name: image.py*


> #!/usr/local/bin/python
>
> #-*- coding:utf8 -*-
>
> importImagefont,ImageDraw
>
> from PIL import Image
>
> im = Image.new("RGB",(400,400))
> #im.show()
>
> draw = ImageDraw.Draw(im)
>
> # use a truetype font
> font=
> ImageFont.truetype("/usr/share/fonts/truetype/ttf-bengali-fonts/lohit_bn.ttf",50)
>
> txt1="ক"
> txt2=" ি"
> txt=txt2+txt1
>
> draw.text((10, 10), unicode(txt,'UTF-8'), font=font)
>

> *When run in terminal of ubuntu9.04 error message displayed as follow:*

74yrs old

unread,
Jan 31, 2010, 8:23:30 AM1/31/10
to indic-ocr
Indu,
It appears that Sri Deepayan Sarkar is too busy, will you please look into matter and guide me how to solve the error message?
With Best Wishes,
-sriranga(77yrsold)

Indu s

unread,
Jan 31, 2010, 11:11:57 PM1/31/10
to indi...@googlegroups.com
import ImageFont, ImageDraw 

it seems you have put space between ImageFont in import statement



When run in terminal of ubuntu9.04 error message displayed as follow:

sriranga@ubuntu:~$ cd Desktop/
sriranga@ubuntu:~/Desktop$ python ./image.py
  File "./image.py", line 6
    import image Font,ImageDraw
                    ^
SyntaxError: invalid syntax
sriranga@ubuntu:~/Desktop$

Request for guidance how to aviod invalid syntax?
With regards,
-sriranga(77yrsold)






--
Thanks & Regards

Indu

Indu s

unread,
Feb 1, 2010, 12:09:18 AM2/1/10
to indi...@googlegroups.com
#!/usr/local/bin/python
#-*- coding:utf8 -*-
import ImageFont,ImageDraw

from PIL import Image

im = Image.new("RGB",(400,400))
#im.show()

draw = ImageDraw.Draw(im)

# use a truetype font
font= ImageFont.truetype("/usr/share/fonts/truetype/ttf-bengali-fonts/lohit_bn.ttf",50)

txt1="ক"
txt2=" ি"
txt=txt2+txt1

draw.text((10, 10), unicode(txt,'UTF-8'), font=font)
im.show()

bbox_sub=im.getbbox() #get the bounding box of the black pixels in the sub image, not the big image
draw.rectangle(bbox_sub)
print bbox_sub

74yrs old

unread,
Feb 1, 2010, 4:32:55 AM2/1/10
to indi...@googlegroups.com
Indu,
thanks for the valuable guidance. I revised the program as per yours. when run in pythonIDLE error message dispalyed as follow:  Also attached copy of image.py for recheck up at your end.Since I am using windows, name of the font has been changed to kannada 'Tunga" This is for your information.
IDLE 2.6.4      ==== No Subprocess ====
>>>
Traceback (most recent call last):
  File "C:\Documents and Settings\Acer\Desktop\image.py", line 5, in <module>
    importImageFont,ImageDraw
NameError: name 'importImageFont' is not defined
>>>

With Choicest Blessings of Supreme Lord,
-sriranga(77yrsold)
image.py

Indu s

unread,
Feb 1, 2010, 4:46:31 AM2/1/10
to indi...@googlegroups.com
Can you please check whether you have installed python Imaging Library.

just run python from command prompt and check the import ImageFont whether its giving error .

Indu s

unread,
Feb 1, 2010, 4:52:53 AM2/1/10
to indi...@googlegroups.com
#!/usr/local/bin/python please change this to the path in windows

74yrs old

unread,
Feb 1, 2010, 5:05:56 AM2/1/10
to indi...@googlegroups.com
Indu,
as suggested correction made. also attached screenshot about search of image font.
image font.JPG

Nandeep Mali

unread,
Feb 1, 2010, 5:22:20 AM2/1/10
to indi...@googlegroups.com
You have written:

ImportImageFont,ImageDraw

Please change it to:

import ImageFont, ImageDraw

Please note the spaces and the comma. 'import' and 'ImageFont' and
'ImageDraw' are different words.

Indu s

unread,
Feb 1, 2010, 5:27:56 AM2/1/10
to indi...@googlegroups.com

pls  check the spacings in

import ImageFont,ImageDraw

from PIL import Image

it seems your python executable path is not correct in screenshot
C:/Python2.6 and in the code you have written as python26

just copy the correct path of your python exe and check

74yrs old

unread,
Feb 1, 2010, 5:40:43 AM2/1/10
to indi...@googlegroups.com
please attached screenshot wherein error message displayed.
syntex error.JPG

Indu s

unread,
Feb 1, 2010, 5:48:23 AM2/1/10
to indi...@googlegroups.com
Just check the path of your font file
and the extension of fontfile Tunga.ttf

74yrs old

unread,
Feb 1, 2010, 6:23:55 AM2/1/10
to indi...@googlegroups.com
Indu,
Verified with folder "fonts" of windows under c:\  it isTunga .ttf (true type)
With Best of Luck,
-sriranga(77yrsold)

Indu s

unread,
Feb 1, 2010, 6:27:17 AM2/1/10
to indi...@googlegroups.com
Then pls set Imagefont as



# use a truetype font
font= ImageFont.truetype("C:\windows\fonts\Tunga.ttf",50)

and check.hope itll work now

74yrs old

unread,
Feb 1, 2010, 6:38:08 AM2/1/10
to indi...@googlegroups.com
Indu,

I copied yours and pasted into original py file and again run but error displayed as follow:

>>
Traceback (most recent call last):
  File "C:\Documents and Settings\Acer\Desktop\image.py", line 15, in <module>

    font= ImageFont.truetype("C:\windows\fonts\Tunga.ttf",50)
  File "C:\Python26\lib\site-packages\PIL\ImageFont.py", line 214, in truetype
    return FreeTypeFont(filename, size, index, encoding)
  File "C:\Python26\lib\site-packages\PIL\ImageFont.py", line 121, in __init__
    self.font = _imagingft.getfont(file, size, index, encoding)
IOError: cannot open resource
>>> whether encoding should be mentioned as utf-8 after 50, ?
With Best Wishes,
-sriranga(77yrsold)

Indu s

unread,
Feb 1, 2010, 6:58:59 AM2/1/10
to indi...@googlegroups.com

    font= ImageFont.truetype("C:\
windows\fonts\Tunga.ttf",50,encoding='utf-8' )

and also is the path like this

C:\WINDOWS\Fonts\Tunga.ttf

check whether the path for ttf file is correct or not..

74yrs old

unread,
Feb 1, 2010, 7:13:19 AM2/1/10
to indi...@googlegroups.com
path is perfectly correct. tried to run but displayed message as follow:
>>>
Traceback (most recent call last):
  File "C:\Documents and Settings\Acer\Desktop\image.py", line 15, in <module>
    font= ImageFont.truetype("C:\WINDOWS\fonts\Tunga.ttf",50,encoding='utf-8' )

74yrs old

unread,
Feb 1, 2010, 7:15:36 AM2/1/10
to indi...@googlegroups.com
thanks for the valuable guidance. noted. tested but still problem for windows.

Indu s

unread,
Feb 1, 2010, 7:16:20 AM2/1/10
to indi...@googlegroups.com
Can you please locate the tunga.ttf and send screenshot

74yrs old

unread,
Feb 1, 2010, 7:33:44 AM2/1/10
to indi...@googlegroups.com
Indu,
as desired by you attached screenshot of  Kannada ttf font
tungttf.JPG

Indu s

unread,
Feb 1, 2010, 10:12:03 PM2/1/10
to indi...@googlegroups.com
As per the image you have send it is in C:\
WINDOWS\Fonts\Tunga.ttf.Before It was not able to locate the ttf file .

So pls set it as # use a truetype font
font= ImageFont.truetype("C:\
WINDOWS\Fonts\Tunga.ttf",50) and it will work.

74yrs old

unread,
Feb 1, 2010, 10:52:34 PM2/1/10
to indi...@googlegroups.com
Indu,
As suggested by you again corrected - vide screenshot attached. similar error message displayed. This time I removed encoding='utf-8' after 50, But still same problem. please check in your ubuntu linux using kannada fonts. - let us see what will happen.Then only we can pinpoint where mistake happens.
With Best Wishes,
-sriranga(77yrsold)
tungttf.JPG

74yrs old

unread,
Feb 1, 2010, 10:54:59 PM2/1/10
to indi...@googlegroups.com
In case, if  it works in ubuntu or Fedora-11, then copy yours working py file forward to me after duly corrected to suit windows platform.
.

74yrs old

unread,
Feb 1, 2010, 11:08:12 PM2/1/10
to indi...@googlegroups.com
_imagingft.getfont(file, size, index, encoding)

It appears the following particulars should be indicated as follows:
file = "C:\Windows\Fonts\Tunga.ttf"  ok
size= 50  is it correct?
index= could not understand.
encoding= encoding='utf-8'   ok?

Kindly re-examine the issue based on above points?.

Indu s

unread,
Feb 1, 2010, 11:56:57 PM2/1/10
to indi...@googlegroups.com
Pls  see the attached file . I dont have windows installed here.I will check with some others once it is available.
test3.py
Screenshot.png

74yrs old

unread,
Feb 2, 2010, 12:22:40 AM2/2/10
to indi...@googlegroups.com
Indu,
Congratulations, Revised py works well after changed to "C:\Windows\Fonts\Tunga.ttf.50) in place of linux folder name  and also changed text2 to text1 + text 2 to text1  now correctly displayed as "ದೂ".
Myearlier I had stated that combination consonant + dependent vowels failed - font by copy and paste into IDLE will not work.  Unable to type in IDLE using barahaIME tool.
With best of Luck,
-sriranga(77yrsold)
Reply all
Reply to author
Forward
0 new messages