def _build_html_image(img, id, div_klass, img_klass, caption=None, show=
    True, image_format='png'):
    """Build a html image from a slice array."""
    html = []
    add_style = u'' if show else u'style="display: none"'
    html.append(u'<li class="%s" id="%s" %s>' % (div_klass, id, add_style))
    html.append(u'<div class="thumbnail">')
    if image_format == 'png':
        html.append(
            u'<img class="%s" alt="" style="width:90%%;" src="data:image/png;base64,%s">'
             % (img_klass, img))
    else:
        html.append(u'<div style="text-align:center;" class="%s">%s</div>' %
            (img_klass, img))
    html.append(u'</div>')
    if caption:
        html.append(u'<h4>%s</h4>' % caption)
    html.append(u'</li>')
    return u'\n'.join(html)
