How to use the cairosvg.surface.PNGSurface.convert function in CairoSVG

To help you get started, we’ve selected a few CairoSVG examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TyVik / geopuzzle / maps / management / commands / info.py View on Github external
def handle(self, *args, **options):
        for lang in ('en', 'ru'):
            for area in Region.objects.language(lang).all():
                infobox = area.infobox

                for key in ('s', 'label'):
                    if key in infobox:
                        del(infobox[key])

                if 'area' in infobox:
                    infobox['area'] = str(int(float(infobox['area'])))

                png_name = 'flags/' + infobox['flag'].split('/')[-1].replace('svg', 'png')
                png_path = default_storage.path(png_name)
                PNGSurface.convert(url=infobox['flag'], write_to=png_path)
                infobox['flag'] = default_storage.url(png_name)

                area.infobox = infobox
                area.save()
github Kozea / CairoSVG / cairosvg / __init__.py View on Github external
def svg2png(bytestring=None, *, file_obj=None, url=None, dpi=96,
            parent_width=None, parent_height=None, scale=1, unsafe=False,
            background_color=None, negate_colors=False, invert_images=False,
            write_to=None, output_width=None, output_height=None):
    return surface.PNGSurface.convert(
        bytestring=bytestring, file_obj=file_obj, url=url, dpi=dpi,
        parent_width=parent_width, parent_height=parent_height, scale=scale,
        background_color=background_color, negate_colors=negate_colors,
        invert_images=invert_images, unsafe=unsafe, write_to=write_to,
        output_width=output_width, output_height=output_height)
github kliment / Printrun / printrun / projectlayer.py View on Github external
dc.Clear()

            if self.slicer == 'Slic3r' or self.slicer == 'Skeinforge':

                if self.scale != 1.0:
                    layercopy = copy.deepcopy(image)
                    height = float(layercopy.get('height').replace('m', ''))
                    width = float(layercopy.get('width').replace('m', ''))

                    layercopy.set('height', str(height * self.scale) + 'mm')
                    layercopy.set('width', str(width * self.scale) + 'mm')
                    layercopy.set('viewBox', '0 0 ' + str(width * self.scale) + ' ' + str(height * self.scale))

                    g = layercopy.find("{http://www.w3.org/2000/svg}g")
                    g.set('transform', 'scale(' + str(self.scale) + ')')
                    stream = cStringIO.StringIO(PNGSurface.convert(dpi = self.dpi, bytestring = xml.etree.ElementTree.tostring(layercopy)))
                else:
                    stream = cStringIO.StringIO(PNGSurface.convert(dpi = self.dpi, bytestring = xml.etree.ElementTree.tostring(image)))

                pngImage = wx.ImageFromStream(stream)

                # print "w:", pngImage.Width, ", dpi:", self.dpi, ", w (mm): ",(pngImage.Width / self.dpi) * 25.4

                if self.layer_red:
                    pngImage = pngImage.AdjustChannels(1, 0, 0, 1)

                dc.DrawBitmap(wx.BitmapFromImage(pngImage), self.offset[0], self.offset[1], True)

            elif self.slicer == 'bitmap':
                if isinstance(image, str):
                    image = wx.Image(image)
                if self.layer_red:
github kliment / Printrun / printrun / projectlayer.py View on Github external
if self.slicer == 'Slic3r' or self.slicer == 'Skeinforge':

                if self.scale != 1.0:
                    layercopy = copy.deepcopy(image)
                    height = float(layercopy.get('height').replace('m', ''))
                    width = float(layercopy.get('width').replace('m', ''))

                    layercopy.set('height', str(height * self.scale) + 'mm')
                    layercopy.set('width', str(width * self.scale) + 'mm')
                    layercopy.set('viewBox', '0 0 ' + str(width * self.scale) + ' ' + str(height * self.scale))

                    g = layercopy.find("{http://www.w3.org/2000/svg}g")
                    g.set('transform', 'scale(' + str(self.scale) + ')')
                    stream = cStringIO.StringIO(PNGSurface.convert(dpi = self.dpi, bytestring = xml.etree.ElementTree.tostring(layercopy)))
                else:
                    stream = cStringIO.StringIO(PNGSurface.convert(dpi = self.dpi, bytestring = xml.etree.ElementTree.tostring(image)))

                pngImage = wx.ImageFromStream(stream)

                # print "w:", pngImage.Width, ", dpi:", self.dpi, ", w (mm): ",(pngImage.Width / self.dpi) * 25.4

                if self.layer_red:
                    pngImage = pngImage.AdjustChannels(1, 0, 0, 1)

                dc.DrawBitmap(wx.BitmapFromImage(pngImage), self.offset[0], self.offset[1], True)

            elif self.slicer == 'bitmap':
                if isinstance(image, str):
                    image = wx.Image(image)
                if self.layer_red:
                    image = image.AdjustChannels(1, 0, 0, 1)
                dc.DrawBitmap(wx.BitmapFromImage(image.Scale(image.Width * self.scale, image.Height * self.scale)), self.offset[0], -self.offset[1], True)