In reportlabs renderPM.drawToFile not working while renderPDF.drawToFile is

Viewed 501

This is my first post here. I'm a newbie. I'm trying to convert some svgs to pgns. I'm creating a chess board diagram using chess-py: Fist I generate the svg file

import os
vipshome = 'c:\\vips-dev-8.7\\bin'
os.environ['PATH'] = vipshome + ';' + os.environ['PATH']
import chess
import chess.svg
# import pyvips
import sys
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM, renderPDF
from IPython.display import SVG


board = chess.Board('rnbqkbnr/pp1ppppp/2p5/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2')
tablero=chess.svg.board(board=board,size=128,coordinates=0)
tablero

Then I save the svg and I'm able to write it as a PDF file by:

# Saving svg file 
outputfile = open('tablero.svg', "w")
outputfile.write(tablero)
outputfile.close()

tempdraw=svg2rlg("tablero.svg")

renderPDF.drawToFile(tempdraw,"tablero.pdf")

However if I try to save it as a PNG, by:

renderPM.drawToFile(tempdraw,"tablero.png",fmt="PNG")

It fails and I get:

AttributeError: 'Image' object has no attribute 'fromstring'

Any help would be appreciated

0 Answers
Related