Converts a PDF to a JPG and places it back onto the FileStorage instance
    passed to it as a BytesIO object.

    Optional meta arguments are:
        * resolution: int or (int, int) used for wand to determine resolution,
        defaults to 300.
        * width: new width of the image for resizing, defaults to 1080
        * bgcolor: new background color, defaults to 'white'

def pdftojpg(filehandle, meta):
    """Converts a PDF to a JPG and places it back onto the FileStorage instance
    passed to it as a BytesIO object.

    Optional meta arguments are:
        * resolution: int or (int, int) used for wand to determine resolution,
        defaults to 300.
        * width: new width of the image for resizing, defaults to 1080
        * bgcolor: new background color, defaults to 'white'
    """
    resolution = meta.get('resolution', 300)
    width = meta.get('width', 1080)
    bgcolor = Color(meta.get('bgcolor', 'white'))
    stream = BytesIO()

    with Image(blob=filehandle.stream, resolution=resolution) as img:
        img.background_color = bgcolor
        img.alpha_channel = False
        img.format = 'jpeg'
        ratio = width / img.width
        img.resize(width, int(ratio * img.height))
        img.compression_quality = 90
        img.save(file=stream)

    stream.seek(0)
    filehandle.stream = stream
    return filehandle