Note that there are some explanatory texts on larger screens.

plurals
  1. POPIL ImageDraw.Draw.text fill attribute raise TypeError : an integer is required
    text
    copied!<p>I'm trying to write text on an image of a QR-Code, but I can't find a way to write in another colour than white (which is pretty useless for a QR-Code).</p> <p>So here is the error page I get (I'm using Django too) :</p> <pre><code>TypeError at /pret/qrcode/ an integer is required Request Method: GET Request URL: http://127.0.0.1:8000/pret/qrcode/ Django Version: 1.6.1 Exception Type: TypeError Exception Value: an integer is required Exception Location: /usr/lib/python2.7/dist-packages/PIL/ImageDraw.py in _getink, line 146 Python Executable: /usr/bin/python Python Version: 2.7.3 Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 114. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/arthur/workspace/PretD/pret/views.py" in qrcodee 160. draw.text((0, 0),"This is a test",(255,255,0),font=font) File "/usr/lib/python2.7/dist-packages/PIL/ImageDraw.py" in text 256. ink, fill = self._getink(fill) File "/usr/lib/python2.7/dist-packages/PIL/ImageDraw.py" in _getink 146. ink = self.draw.draw_ink(ink, self.mode) Exception Type: TypeError at /pret/qrcode/ Exception Value: an integer is required </code></pre> <p>In my view I have: </p> <pre><code> foo = qrcode.make(request.user.email) foo.format = "PNG" foo.save('pret/static/media/qrcode.png') font = ImageFont.truetype("pret/static/DejaVuSans.ttf", 20) img=Image.open("pret/static/media/qrcode.png") draw = ImageDraw.Draw(img) draw.text((0, 0),"String test",(255,255,0),font=font) draw = ImageDraw.Draw(img) del draw img.save('pret/static/media/qrcode.png') </code></pre> <p>with these imports:</p> <pre><code>import ImageDraw import ImageFont import Image </code></pre> <p>NB: Python couldn't find "PIL" when I tried to write</p> <pre><code>import PIL from PIL import Image, ImageFond, ImageDraw </code></pre> <p>but it worked without mentioning it, I guess it's already included in Django by default. Plus, we can see in the traceback that Python does indeed look into /dist-packages/PIL</p> <p>Thank you for your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload