'Parses an IMG element and converts it into an Image for ReportLab
@param html: the IMG element  to convert
@param uploadfolder: an optional uploadfolder in which to find the file
@return: a list containing an Image that ReportLab can use
@note: The `src` attribute of the image must either
point to a static resource, directly to a file, or to an upload.'

@staticmethod
def parse_img(html, uploadfolder=None):

    I = None
    src = html.attributes.get('_src')
    if src:
        if uploadfolder:
            src = src.rsplit('/', 1)
            src = os.path.join(uploadfolder, src[1])
        else:
            request = current.request
            base_url = ('/%s/' % request.application)
            STATIC = ('%sstatic' % base_url)
            if src.startswith(STATIC):
                src = src.split(base_url)[(-1)]
                src = src.replace('/', os.sep)
                src = os.path.join(request.folder, src)
            else:
                src = src.rsplit('/', 1)
                src = os.path.join(request.folder, 'uploads', src[1])
        if os.path.exists(src):
            from reportlab.platypus import Image
            I = Image(src)
    if (not I):
        return None
    iwidth = I.drawWidth
    iheight = I.drawHeight
    resolution = 96
    if ('_height' in html.attributes):
        height = ((int(html.attributes['_height']) * inch) / resolution)
        width = (iwidth * (height / iheight))
    elif ('_width' in html.attributes):
        width = ((int(html.attributes['_width']) * inch) / resolution)
        height = (iheight * (width / iwidth))
    else:
        height = (1.0 * inch)
        width = (iwidth * (height / iheight))
    I.drawHeight = height
    I.drawWidth = width
    return [I]
