Hi Guys,
Any idea on how to import SVG files and use them as images in classic wxPython?
Thanks,
Emad
Hi Guys,
Any idea on how to import SVG files and use them as images in classic wxPython?
Thanks,
Emad
pip install cairosvg
Then cairosvg.svg2png() and use wxPNGHandler
On 29/04/2016 01:23, Emad Dlala wrote:
Hi Guys,
Any idea on how to import SVG files and use them as images in classic
wxPython?Thanks,
Emad--
You received this message because you are subscribed to the Google
Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com
<mailto:wxpython-users+unsubscribe@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.
--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
Hi Steve,
I have tried cairosvg and many other versions of cairo extensions but none of them gave me desirable results. Most of the time the quality of the image isn’t good. But I just now found that PyQt4 can be used to convert svg to png. It gives excellent quality images.
from PyQt4.QtSvg import *
from PyQt4.QtGui import *
def convertSvgToPng(svgFilepath,pngFilepath,width):
r=QSvgRenderer(svgFilepath)
height=r.defaultSize().height()*width/r.defaultSize().width()
i=QImage(width,height,QImage.Format_ARGB32)
p=QPainter(i)
convertSvgToPng(‘Draft_Finish.svg’,‘Draft_Finish.png’,200)
Thanks,
Emad
On Thu, Apr 28, 2016 at 9:03 PM, Steve (Gadget) Barnes gadgetsteve@live.co.uk wrote:
On 29/04/2016 01:23, Emad Dlala wrote:
Hi Guys,
Any idea on how to import SVG files and use them as images in classic
wxPython?
Thanks,
Emad
–
You received this message because you are subscribed to the Google
Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com
For more options, visit https://groups.google.com/d/optout.
pip install cairosvg
Then cairosvg.svg2png() and use wxPNGHandler
–
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I noticed I didn’t copy the complete function
def convertSvgToPng(svgFilepath,pngFilepath,width):
r=QSvgRenderer(svgFilepath)
height=r.defaultSize().height()*width/r.defaultSize().width()
i=QImage(width,height,QImage.Format_ARGB32)
p=QPainter(i)
r.render(p)
i.save(pngFilepath)
p.end()
convertSvgToPng(‘Draft_Finish.svg’,‘Draft_Finish.png’,200)
On Fri, Apr 29, 2016 at 10:52 AM, Emad Dlala emad.dlala@gmail.com wrote:
Hi Steve,
I have tried cairosvg and many other versions of cairo extensions but none of them gave me desirable results. Most of the time the quality of the image isn’t good. But I just now found that PyQt4 can be used to convert svg to png. It gives excellent quality images.
from PyQt4.QtSvg import *
from PyQt4.QtGui import *
def convertSvgToPng(svgFilepath,pngFilepath,width):
r=QSvgRenderer(svgFilepath)
height=r.defaultSize().height()*width/r.defaultSize().width()
i=QImage(width,height,QImage.Format_ARGB32)
p=QPainter(i)
convertSvgToPng(‘Draft_Finish.svg’,‘Draft_Finish.png’,200)
Thanks,
Emad
On Thu, Apr 28, 2016 at 9:03 PM, Steve (Gadget) Barnes gadgetsteve@live.co.uk wrote:
On 29/04/2016 01:23, Emad Dlala wrote:
Hi Guys,
Any idea on how to import SVG files and use them as images in classic
wxPython?
Thanks,
Emad
–
You received this message because you are subscribed to the Google
Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com
For more options, visit https://groups.google.com/d/optout.
pip install cairosvg
Then cairosvg.svg2png() and use wxPNGHandler
–
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If you can use an external tool to convert, then I"d take a look at InkScape – it’s a GUI vector graphics program, but it can be called on the command line to render SVG – and does a very nice job of it.
-CHB
On Fri, Apr 29, 2016 at 10:52 AM, Emad Dlala emad.dlala@gmail.com wrote:
Hi Steve,
I have tried cairosvg and many other versions of cairo extensions but none of them gave me desirable results. Most of the time the quality of the image isn’t good. But I just now found that PyQt4 can be used to convert svg to png. It gives excellent quality images.
from PyQt4.QtSvg import *
from PyQt4.QtGui import *
def convertSvgToPng(svgFilepath,pngFilepath,width):
r=QSvgRenderer(svgFilepath)
height=r.defaultSize().height()*width/r.defaultSize().width()
i=QImage(width,height,QImage.Format_ARGB32)
p=QPainter(i)
convertSvgToPng(‘Draft_Finish.svg’,‘Draft_Finish.png’,200)
Thanks,
Emad
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
–
On Thu, Apr 28, 2016 at 9:03 PM, Steve (Gadget) Barnes gadgetsteve@live.co.uk wrote:
On 29/04/2016 01:23, Emad Dlala wrote:
Hi Guys,
Any idea on how to import SVG files and use them as images in classic
wxPython?
Thanks,
Emad
–
You received this message because you are subscribed to the Google
Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com
For more options, visit https://groups.google.com/d/optout.
pip install cairosvg
Then cairosvg.svg2png() and use wxPNGHandler
–
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception