0

i m using Python 3.3,and i have installed(just excute the downloaded file .exe,no need any setting?) aspell PIL from below link,unfortunately i import PIL are error unresolved PIL. why?

http://www.lfd.uci.edu/~gohlke/pythonlibs/

import PIL
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
font = ImageFont.truetype("C:/arial.ttf",25)
img=Image.new("RGBA", (200,200),(120,20,20))
draw = ImageDraw.Draw(img)
draw.text((0, 0),"This is a test",(255,255,0),font=font)
draw = ImageDraw.Draw(img)
draw = ImageDraw.Draw(img)
img.save("a_test.png")

or have any ideas without using PIL to draw the text on a image?

  • Check out this question: http://stackoverflow.com/questions/3896286/image-library-for-python-3 – Mark Ransom Feb 07 '13 at 18:22
  • ya.i did checked the page,i m using http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil this PIL,but still can't import PIL.i have mention in my question already, i did –  Feb 07 '13 at 18:23
  • `pycairo` is available for Python 3.x, have you considered it ? – mmgp Feb 08 '13 at 21:03

3 Answers3

2

Pillow is the continuation of Python Imaging Library that has been updated to work with Python 3. This should fix your unresolved PIL problem.

Other options for drawing text on an image in recent Python exist:

  • Pygame is an SDL 1.2 wrapper that supports Python 3 since Pygame 1.9.2.
  • Wand is an ImageMagick wrapper built on ctypes.
  • gdmodule wraps GD, but its installer appears to be Linux-only. It won't help you under Windows (cf. "C:/arial.ttf") but it might help others with the same problem.
Damian Yerrick
  • 4,602
  • 2
  • 26
  • 64
1

Because it haven't been released for 3.3 yet.

"The current free version is PIL 1.1.7. This release supports Python 1.5.2 and newer, including 2.5 and 2.6. A version for 3.X will be released later." -taken from PILs homepage.

If you want to use PIL use Python 2.6. The 3.X version of Python changed python a bit so it's not fully backwards compatible.

I recommend you use older version of Python instead of 3.X, unless you have a REALLY good reason to use 3.X.

Wertilq
  • 175
  • 1
  • 10
  • @Wertilq have any ideas without using PIL to draw the text on a image? –  Feb 07 '13 at 15:42
  • Do you NEED to use Python 3.3? My girlfriend is currently doing a uni course on python and they use 2.7.2 there. – Wertilq Feb 07 '13 at 16:34
  • C.Y. Images are just data. If you know the image format you can "draw a line" and turn that data into what a browser would understand as an image. So if you want to manipulate images without PIL then learn the relevant image format and layout and create a function that does what you need it to in code! – Paul Collingwood Feb 07 '13 at 17:30
  • @PaulC, PNG images are going to be difficult to write out without library support. Converting a font to bitmap form is also difficult, unless you can produce each glyph as a separate bitmap using an offline utility. – Mark Ransom Feb 07 '13 at 18:25
  • Absolutely! I was really trying to make the point to the OP that drawing on images from scratch is *hard* which is why there are libraries for that. But ultimately that images are just data also and if you really want you can manipulate them "by hand". – Paul Collingwood Feb 07 '13 at 18:27
1

Using opencv

import cv2
font = cv2.FONT_HERSHEY_SIMPLEX 
orgin = (50, 50) 
fontScale = 1
color = (255, 0, 0) 
thickness = 2

Using cv2.putText() method

image = cv2.putText(image, 'OpenCV', org, font, fontScale, color, thickness, cv2.LINE_AA) 
Kukesh
  • 490
  • 1
  • 5
  • 18