当前位置: 首页>>代码示例>>Python>>正文


Python cairosvg.svg2png方法代码示例

本文整理汇总了Python中cairosvg.svg2png方法的典型用法代码示例。如果您正苦于以下问题:Python cairosvg.svg2png方法的具体用法?Python cairosvg.svg2png怎么用?Python cairosvg.svg2png使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cairosvg的用法示例。


在下文中一共展示了cairosvg.svg2png方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_integration_bot_avatar

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def create_integration_bot_avatar(logo_path: str, bot_avatar_path: str) -> None:
    if logo_path.endswith('.svg'):
        avatar = cairosvg.svg2png(
            url=logo_path, output_width=DEFAULT_AVATAR_SIZE, output_height=DEFAULT_AVATAR_SIZE)
    else:
        with open(logo_path, 'rb') as f:
            image = f.read()
        square_image = create_square_image(image)
        avatar = resize_avatar(square_image)

    os.makedirs(os.path.dirname(bot_avatar_path), exist_ok=True)
    with open(bot_avatar_path, 'wb') as f:
        f.write(avatar) 
开发者ID:zulip,项目名称:zulip,代码行数:15,代码来源:generate_integration_bots_avatars.py

示例2: __init__

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def __init__(self, league='WNBA',
                 team_id='1611661319',
                 season_year='2017-18'):

        # Controlling the parameters depending on the endpoint
        if league == 'WNBA':
            team_str = ID_TO_TEAM_WNBA[team_id]
            response = requests.get(BASE_WNBA_LOGO_URL.format(team=team_str))
        elif league == 'NBA':
            team_str = ID_TO_TEAM_NBA[team_id]
            response = requests.get(BASE_NBA_LOGO_URL.format(team=team_str,
                                                             year=season_year))
        elif league == 'G':
            team_str = ID_TO_TEAM_G_LEAGUE[team_id]
            response = requests.get(BASE_G_LEAGUE_LOGO_URL.format(team=team_str))

        new_bites = svg2png(bytestring=response.content,
                            write_to=None)
        im = Image.open(BytesIO(new_bites))
        self.image = im 
开发者ID:basketballrelativity,项目名称:py_ball,代码行数:22,代码来源:image.py

示例3: __svg_to_Image

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def __svg_to_Image(self, svg_string):
      '''
        gets svg content and returns a PIL.Image object
      '''
      import cairosvg
      import io
      in_mem_file = io.BytesIO()
      cairosvg.svg2png(bytestring=svg_string, write_to=in_mem_file)
      return Image.open(io.BytesIO(in_mem_file.getvalue())) 
开发者ID:manatools,项目名称:dnfdragora,代码行数:11,代码来源:updater.py

示例4: fromSvg

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def fromSvg(svgData):
        pngData = cairosvg.svg2png(bytestring=svgData)
        return Raster(pngData) 
开发者ID:cduck,项目名称:drawSvg,代码行数:5,代码来源:raster.py

示例5: fromSvgToFile

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def fromSvgToFile(svgData, outFile):
        cairosvg.svg2png(bytestring=svgData, write_to=outFile)
        return Raster(None, pngFile=outFile) 
开发者ID:cduck,项目名称:drawSvg,代码行数:5,代码来源:raster.py

示例6: generate_cover

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def generate_cover(app):
    logger.info('Generating cover image...')
    if svg2png is None:
        return
    # end if
    try:
        svg_file = os.path.join(app.output_path, 'cover.svg')
        svg = random_cover(
            title=app.crawler.novel_title,
            author=app.crawler.novel_author,
        )

        with open(svg_file, 'w', encoding='utf-8') as f:
            f.write(svg)
            logger.debug('Saved a random cover.svg')
        # end with

        png_file = os.path.join(app.output_path, 'cover.png')
        svg2png(bytestring=svg.encode('utf-8'), write_to=png_file)
        logger.debug('Converted cover.svg to cover.png')

        return png_file
    except Exception:
        logger.exception('Failed to generate cover image: %s', app.output_path)
        return None
    # end try
# end def 
开发者ID:dipu-bd,项目名称:lightnovel-crawler,代码行数:29,代码来源:downloader.py

示例7: render_png

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def render_png(self, request):
        svg_data = self.make_svg(request)
        png_data = cairosvg.svg2png(bytestring=svg_data)
        return aiohttp.web.Response(body=png_data, content_type="image/png") 
开发者ID:niklasf,项目名称:web-boardimage,代码行数:6,代码来源:server.py

示例8: make_linux

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def make_linux():
    if not os.path.exists('linux'):
        os.makedirs('linux')
    for file in os.listdir('svg'):
        if file.endswith(".svg"):
            svg2png(url="svg/"+file, write_to="linux/" + file.split('.')[0] + ".png", parent_width=256, parent_height=256) 
开发者ID:HackeSta,项目名称:atom-icons,代码行数:8,代码来源:make.py

示例9: get_size_name

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def get_size_name(size):
    if size[1] == 144:
        return str(size[0]//2) + 'x' + str(size[0]//2) + '@2x'
    return str(size[0]) + 'x' + str(size[0])

# def prep_macOS():
#     if not os.path.exists('macOS'):
#         os.makedirs('macOS')
#     for file in os.listdir('svg'):
#         if file.endswith(".svg"):
#             if not os.path.exists('macOS/'+file.split('.')[0] + '.iconset/'):
#                 os.makedirs('macOS/'+file.split('.')[0] + '.iconset/')
#             for size in ICNS_SIZES:
#                 svg2png(url="svg/"+file, write_to="macOS/"+file.split('.')[0] + '.iconset/icon_' + get_size_name(size) + ".png", parent_width=size[0], parent_height=size[0], dpi=size[1]) 
开发者ID:HackeSta,项目名称:atom-icons,代码行数:16,代码来源:make.py

示例10: png_svg

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def png_svg(self, path, size):
		with open(path, 'rb') as f:
			path = f.read()
		s = bytes(str(size), encoding="utf-8")
		b = path.replace(b"<svg ", b"<svg width=\"" + s + b"px\" height=\"" + s + b"px\" ")
		path = BytesIO(cairosvg.svg2png(b))
		return path 
开发者ID:NotSoSuper,项目名称:NotSoBot,代码行数:9,代码来源:Fun.py

示例11: svg2png

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def svg2png(svg):
    # assume that 'cairosvg' exists
    import cairosvg
    cairosvg.svg2png(url=svg, write_to=svg[:-4] + '.png', dpi=250)
    return svg[:-4] + '.png' 
开发者ID:leegao,项目名称:readme2tex,代码行数:7,代码来源:render.py

示例12: dashExport

# 需要导入模块: import cairosvg [as 别名]
# 或者: from cairosvg import svg2png [as 别名]
def dashExport(request, code):
  """
  Handler function to export dashboard to SVG, PDF, or PNG.

  Args:
    request: Django request object.
    exportType: A string corresponding to the format for export.
    code: A code to identify the serialized data stored in the session field of
      the Django request.

  Returns:
    A file that corresponds to the dashboard encoded by `serial`, in the format
    requested.

  Raises:
    ValueError: Thrown when an invalid export type is passed in.
  """
  if not settings.EXPORT_SERVICE_PORT:
    raise ValueError('Received an export request, but exporting is not enabled')

  data       = request.session[code]
  serial     = data['serial']
  exportType = data['exportType']

  svg = _getSvg(request, serial)
  res, contentType = None, None

  if   exportType == 'svg':
    res = svg
    contentType = "image/svg+xml"
  else:
    import cairosvg
    # pylint: disable = E1101
    # Pylint does not recognize svg2pdf/svg2png method in cairosvg
    if exportType == 'pdf':
      res = cairosvg.svg2pdf(svg)
      contentType = "application/pdf"
    elif exportType == 'png':
      res = cairosvg.svg2png(svg)
      contentType = "image/png"
    else:
      raise ValueError("views.export.dashExport: Invalid export format, %s" % exportType)

  response = HttpResponse(res, content_type=contentType)
  response['Content-Disposition'] = "attachment;filename=dashboard." + exportType
  return response

#### Helper methods for rendering 
开发者ID:Polychart,项目名称:builder,代码行数:50,代码来源:export.py


注:本文中的cairosvg.svg2png方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。