In my dash application, I have a dcc.Graph
component that renders an annotated image:
I would like to export this as a full-resolution tiff file. When I convert the undelying image into a numpy array for export using the following code:
def plotly_fig2array(fig, array):
# convert Plotly fig to an array
fig_bytes = fig.to_image(format="webp", width=array.shape[1], height=array.shape[0])
buf = io.BytesIO(fig_bytes)
img = Image.open(buf)
return np.array(Image.fromarray(np.asarray(img)).convert('RGB')).astype(np.uint8)
The text annotations are barely visible in the output image along the bottom of the border:
It appears that are significant distortion of the annotations is happening during the conversion.