Appengine - Reportlab (Get photos from the model)

I am using Reportlab to create a PDF file. Unable to get photo from model.

#Personal Info             
  p.drawImage('myPhoto.jpg', 40, 730)
  p.drawString(50, 670, 'Your name:' + '%s' % user.name)
  p.drawImage (50, 640, 'Photo: %s' % (user.photo))

When I create the generated PDF file, I got this error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 513, in __call__
    handler.post(*groups)
  File "C:\Users\hp\workspace\myApp\src\main.py", line 419, in post
    p.drawImage (50, 640, 'Photo: %s'  %                  (user.photo))
  File "reportlab.zip\reportlab\pdfgen\canvas.py", line 825, in drawImage
  File "reportlab.zip\reportlab\pdfbase\pdfdoc.py", line 2076, in __init__
  File "C:\Python25\lib\ntpath.py", line 189, in splitext
    i = p.rfind('.')
AttributeError: 'int' object has no attribute 'rfind'

If I comment on the line that n.ΒΊ 419, which calls the photo, everything goes well. I have already tested in the Datastore Viewer, and the models are fine.

Can someone point out what is going wrong?

Should I use% s instead of str? But throws the same mistake.

+5
source share
1 answer

API ReportLab, drawImage() , x, y ', , 'x, y, string'.

drawImage() ImageReader.

, ImageReader .

Update:

, , ImageReader "", "imagem" ( ) drawImage:

image = ImageReader(user.photo) 
p.drawImage(imagem)

, user.photo?

2:

NoneType - , user.photo , None?

, blob str, ImageReader StringIO - , blob StringIO, ImageReader, :

import StringIO
image = ImageReader(StringIO.StringIO(user.photo))
p.drawImage(image)

, , ImageReader('http://www.reportlab.com/rsrc/encryption.gif') , , API, (.. urlfetch).

3:

ReportLab.

2.4 ReportLab utils.py:

def _isPILImage(im):
    try:
        return isinstance(im,Image.Image)
    except ImportError:
        return 0

class ImageReader(object):
    "Wraps up either PIL or Java to get data from bitmaps"
    _cache={}
    def __init__(self, fileName):
        ...
        if _isPILImage(fileName):

ImageReader _isPILImage, , PIL. PIL , Image is None Image.Image in _isPILImage AttributeError: 'NoneType' object has no attribute 'Image'., .

, ReportLab . , , . " PDF ", , . , , , 2.4, , - , .

, ReportLab PIL (.. ) JPEG ( ).

, :

def get(self, image): 
    if image is not None: 
        image = ImageReader(StringIO.StringIO(user.photo)) 
        p.drawImage(40, 700, image) 
        p.setLineWidth(.3) 
        p.setFont('Helvetica', 10) 
        p.line(50, 660, 560, 660)

, drawImage() "x, y, image", "image, x, y".

-, , p (, ?).

-, get() - - URL- webapp.WSGIApplication()? , None, .

4:

Imaging Library not available, unable to import bitmaps only jpegs, , , ReportLab jpeg, . , jpeg , blob, , , jpeg , ReportLab .

ReportLab lib\utils.py ( 578 2.5):

try:
    self._width,self._height,c=readJPEGInfo(self.fp)
except:
    raise RuntimeError('Imaging Library not available, unable to import bitmaps only jpegs')

:

self._width,self._height,c=readJPEGInfo(self.fp)

, readJPEGInfo(), .

, , , .jpg, , :

imagem = canvas.ImageReader(StringIO.StringIO(open('file.jpg', 'rb').read()))

jpeg , ImageReader, blob.

, , blob , . , jpeg ( ReportLab).

5:

:

photo = images.resize(self.request.get('photo'), 32, 32)

output_encoding, PNG. :

photo = images.resize(self.request.get('photo'), 32, 32, images.JPEG)
+12

All Articles