I have a Python program that creates a lot of plots with matplotlib. These images are then compiled into a PDF report using Python fpdf module.
The problem is, with PNGs produced with matplotlib, this is extremely slow. Each image takes approximately 2.5 seconds to add with FPDF.image() function. However, PNG images produced with MATLAB are added in milliseconds.
If I take the matplotlib images and pass them through ImageMagick with the '-alpha off' option, the images are added to the PDF in milliseconds. So, it seems alpha layers may be to blame, but I cannot figure out how to control this in matplotlib. I have tried using:
fig.savefig(savepath + ".png", transparent=False)
Yes the images still take 2.5 seconds to add to the PDF. So maybe it is something else that ImageMagick is doing to the images.
Processing all the images through ImageMagick takes about the same time per image as adding the originals to the PDF, so that is not an option to save time.
They are very simple plots. So I am not sure what could be the issue.
Here is an example image:
Although I wonder if everything about this image is preserved from uploading it here...
Edit: When I load the image in GIMP, I do see the alpha channel in the originals but not the ImageMagick outputs. So, that seems to be it, so how do I prevent matplotlib from adding the Alpha Channel?