I want to generated image from html to jpeg. So I'm using imgkit and try to generated image. Image is generated correctly. According to imgkit documentation I tried to read image to variable and save it to mongodb collection using mongoengine. This code I used to read it to variable
# Use False instead of output path to save pdf to a variable
img = imgkit.from_url('http://example.com', False)And this is the way that I tried to store it in db collection.class Page(Document):
image = ImageField() path_wkthmltoimage = r'C:/Program Files/wkhtmltopdf/bin/wkhtmltoimage.exe'
config = imgkit.config(wkhtmltoimage=path_wkthmltoimage)
options = {
'format': 'jpeg',
'quality': '40'
}
img = imgkit.from_url('http://example.com', False, config=config, options=options)
myimage = open(img, 'rb')
Page.image.put(myimage)
Page.save()But It gives this errorError:myimage = open(img, 'rb')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byteHow I store that image in db collection?
