def convert_unit(value, ppi=72):
    """
    Function to convert size given in some unit to pixels, following the
    https://www.w3.org/TR/2008/REC-CSS2-20080411/syndata.html#length-units

    Parameters:
    -----------

    value, str or int:
        The given size followed by it's unit. Fixed units are (in, cm,
        mm, pt, pc). Relative units are (em, ex, %)

    ppi, int, optional:
        The number of pixel per inch (Latex use 72)
    """
    value = str(value)
    if 'px' in value:
        value = '%0.1f' % float(value.replace('px', ''))
    if 'mm' in value:
        value = '%fcm' % (float(value.replace('mm', '')) * 10 ** -1)
    if 'cm' in value:
        value = '%fin' % (float(value.replace('cm', '')) * (1 / 2.54))
    if 'pc' in value:
        value = '%fin' % float(value.replace('pc', '') * 12)
    if 'pt' in value:
        value = '%fin' % (float(value.replace('pt', '')) * (1 / 72.0))
    if 'in' in value:
        out = float(value.replace('in', '')) * ppi
    else:
        out = float(value)
    return out
