mirror of
https://github.com/ankitects/anki.git
synced 2025-11-12 07:37:11 -05:00
convert svgs to png on import
This commit is contained in:
parent
a7e6ffe73d
commit
582f89155d
1 changed files with 12 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
|
from PyQt4.QtSvg import *
|
||||||
import re, os, sys, tempfile, urllib2
|
import re, os, sys, tempfile, urllib2
|
||||||
from anki.utils import stripHTML, tidyHTML, canonifyTags
|
from anki.utils import stripHTML, tidyHTML, canonifyTags
|
||||||
from anki.sound import playFromText
|
from anki.sound import playFromText
|
||||||
|
|
@ -571,6 +572,17 @@ class FactEditor(object):
|
||||||
file = ui.utils.getFile(self.parent, _("Add an image"), "picture", key)
|
file = ui.utils.getFile(self.parent, _("Add an image"), "picture", key)
|
||||||
if not file:
|
if not file:
|
||||||
return
|
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)
|
self._addPicture(file, widget=w)
|
||||||
|
|
||||||
def _addPicture(self, file, widget=None):
|
def _addPicture(self, file, widget=None):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue