def url_to_img_element(url, name, width, height, unit='px'):
    """Convert a given URL to a HTML img element."""
    style = None
    if width is not None and height is not None:
        style = 'width:{width}{unit};height:{height}{unit};'.format(
            width=width, height=height, unit=unit)
    elif width is not None:
        style = 'width:{width}{unit};'.format(width=width, unit=unit)
    elif height is not None:
        style = 'height:{height}{unit};'.format(height=height, unit=unit)

    html = '<img src="{}"'.format(url)
    if name is not None:
        html += ' alt="{}"'.format(name)
    if style is not None:
        html += ' style="{}"'.format(style)
    html += '>'
    return html