From 582f89155d2f027316ca5119d0a99d46a9e62050 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 24 Jan 2009 18:01:45 +0900 Subject: [PATCH] convert svgs to png on import --- ankiqt/ui/facteditor.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index b640d9d2d..23838c00a 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -4,6 +4,7 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * +from PyQt4.QtSvg import * import re, os, sys, tempfile, urllib2 from anki.utils import stripHTML, tidyHTML, canonifyTags from anki.sound import playFromText @@ -571,6 +572,17 @@ class FactEditor(object): file = ui.utils.getFile(self.parent, _("Add an image"), "picture", key) if not file: return + if file.lower().endswith(".svg"): + # convert to a png + s = QSvgRenderer(file) + i = QImage(s.defaultSize(), QImage.Format_ARGB32_Premultiplied) + p = QPainter() + p.begin(i) + s.render(p) + p.end() + (fd, name) = tempfile.mkstemp(prefix="anki", suffix=".png") + file = unicode(name, sys.getfilesystemencoding()) + i.save(file) self._addPicture(file, widget=w) def _addPicture(self, file, widget=None):