views:

297

answers:

2

I'm trying to open a PNG image and write some text to it (a watermark) via QImage and QPainter. The code works 100% on Linux but when I run it on Windows XP (haven't tested with any other versions of Windows) the text is never written to the image. I have the code in a try/except block, but no errors are returned.

image = QtGui.QImage('demo.png')

painter = QtGui.QPainter()
painter.begin(image)
painter.setOpacity(0.8)
painter.setPen(QtCore.Qt.blue)
painter.setFont(QtGui.QFont('arial', 12))
painter.drawText(image.rect(), QtCore.Qt.AlignCenter, 'Watermark')
painter.end()

image.save('demo.png')

Using Python 2.6.2, PyQt 4.5.4

Any ideas?

A: 

First thing that comes to my mind is maybe it isn't finding the specified font on Windows.

retracile
eh, the docs indicate that if the specified family isn't found, it'll pick another one. Sounds to me like mgb's answer is more likely right. If it turns out that way, I'll delete mine.
retracile
A: 

My guess would be that whatever png lib you are using on Windows doesn't do tranparency (properly)

Martin Beckett