hi
i'm trying to fetch images from a url and then pasre it to odoo as a base64
but whenever there is an image with webp extension i'm unable to write that image into odoo can i get a free solution for this i have this piece of code
def fetch_image(url):
i'm trying to fetch images from a url and then pasre it to odoo as a base64
but whenever there is an image with webp extension i'm unable to write that image into odoo can i get a free solution for this i have this piece of code
def fetch_image(url):
headers = {
"User-Agent": "Mozilla/5.0",
"Accept": "image/avif,image/webp,image/apng,image/,/*;q=0.8",
}
response = requests.get(url, headers=headers)
if response.status_code != 200:
return False
content = response.content
img_type = imghdr.what(None, content)
if img_type == "webp":
# _logger.info(f"url------{url}------")
img = Image.open(BytesIO(content)).convert("RGB")
buffer = BytesIO()
img.save(buffer, format="PNG")
img_data = base64.b64encode(buffer.getvalue()).decode('utf-8')
return img_data
elif img_type in ("jpeg", "jpg", "png"):
return base64.b64encode(content).decode('utf-8')
else:
return False