I'm trying to read an svg file and convert it to png. I'm able to save the file and upload it properly:
import matplotlib.pyplot as plt
from cairo import svg2png
from scipy import misc
svg2png(url = r'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/410.svg',write_to='test.png')
im = misc.imread('test.png')
plt.imshow(im)
I would like to skip the saving part. I tried this:
import cv2
I = svg2png(url = r'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/410.svg')
nparr = np.fromstring(I, np.uint8)
img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
im = cv2.cvtColor(img_np,cv2.COLOR_BGR2RGB)
but it is not the same as the image in the first case since it is not loading the 4th dimension of the png (i.e. the mask) and I get a black border around the image.
Any ideas how to solve this issue?