I am trying to convert an imgkit image into a PIL image to modify it. imgkit successfully converted the html to image when I tried to use a file. When I use BytesIO and try to convert to a PIL image, im getting an error.
Here is my code:
img = imgkit.from_string(template.render(a=elements, r=range(len(elements))), False, config=config)
bytesImg = BytesIO(img)
bytesImg.seek(0)
image = Image.open(bytesImg) #error here
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x102082680>
I already saw this and this. Am I incorrectly converting the imgkit image to bytes or is there some other error?
Using Pillow 8.1 Python 3.9 and imgkit 1.0.2
imgkit was converting the html to pdf because the config variable was messed up.
use
which wkhtmltoimage
to find path to wkhtmltoimage and set
config = imgkit.config(wkhtmltoimage="path found")