Hello guys, I have notice that when we attached an image in the document the image like change quality for 85%? and when I locate the method in frappe/utils/image.py I found this method that the quality really change to 85?
So my question here is:
How do I set the quality to 100?
Here is the method from frappe/utils/image.py
def optimize_image(content, content_type, max_width=1024, max_height=768, optimize=True, quality=85):
if content_type == “image/svg+xml”:
return content
try:
image = Image.open(io.BytesIO(content))
exif = image.getexif()
width, height = image.size
max_height = max(min(max_height, height * 0.8), 200)
max_width = max(min(max_width, width * 0.8), 200)
image_format = content_type.split("/")[1]
size = max_width, max_height
image.thumbnail(size, Image.Resampling.LANCZOS)
output = io.BytesIO()
image.save(
output,
format=image_format,
optimize=optimize,
quality=quality,
save_all=True if image_format == "gif" else None,
exif=exif,
)
optimized_content = output.getvalue()
return optimized_content if len(optimized_content) < len(content) else content
except Exception as e:
frappe.msgprint(frappe._("Failed to optimize image: {0}").format(str(e)))
return content