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


Python BaseEngine.convert_svg_to_png方法代码示例

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


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

示例1: BaseEngineTestCase

# 需要导入模块: from thumbor.engines import BaseEngine [as 别名]
# 或者: from thumbor.engines.BaseEngine import convert_svg_to_png [as 别名]
class BaseEngineTestCase(TestCase):
    def get_context(self):
        cfg = Config(
            SECURITY_KEY='ACME-SEC',
            ENGINE='thumbor.engines',
        )
        cfg.STORAGE = 'thumbor.storages.no_storage'

        return Context(config=cfg)

    def flip_horizontally(self):
        ((a, b), (c, d)) = self.image
        self.image = (
            (b, a),
            (d, c)
        )

    def flip_vertically(self):
        ((a, b), (c, d)) = self.image
        self.image = (
            (c, d),
            (a, b)
        )

    def rotate(self, value):
        ((a, b), (c, d)) = self.image
        if value == 270:
            self.image = (
                (c, a),
                (d, b)
            )
        elif value == 180:
            self.image = (
                (d, c),
                (b, a)
            )
        elif value == 90:
            self.image = (
                (b, d),
                (a, c)
            )

    def setUp(self):
        self.image = (
            (1, 2),
            (3, 4)
        )
        self.context = self.get_context()
        self.engine = BaseEngine(self.context)
        self.engine.flip_horizontally = mock.MagicMock()
        self.engine.flip_horizontally.side_effect = self.flip_horizontally
        self.engine.flip_vertically = mock.MagicMock()
        self.engine.flip_vertically.side_effect = self.flip_vertically
        self.engine.rotate = mock.MagicMock()
        self.engine.rotate.side_effect = self.rotate

    def test_create_engine(self):
        expect(self.engine).to_be_instance_of(BaseEngine)

    def test_convert_svg_to_png(self):
        buffer = """<svg width="10px" height="20px" viewBox="0 0 10 20"
                    xmlns="http://www.w3.org/2000/svg">
                        <rect width="100%" height="10" x="0" y="0"/>
                    </svg>"""
        self.engine.convert_svg_to_png(buffer)
        expect(self.engine.extension).to_equal('.png')

    def test_convert_svg_with_xml_preamble_to_png(self):
        buffer = """<?xml version="1.0" encoding="utf-8"?>
                    <svg width="10px" height="20px" viewBox="0 0 10 20"
                    xmlns="http://www.w3.org/2000/svg">
                        <rect width="100%" height="10" x="0" y="0"/>
                    </svg>""".encode('utf-8')
        self.engine.convert_svg_to_png(buffer)
        expect(self.engine.extension).to_equal('.png')

    def test_convert_svg_utf16_to_png(self):
        buffer = """<?xml version="1.0" encoding="utf-16"?>
                    <svg width="10px" height="20px" viewBox="0 0 10 20"
                    xmlns="http://www.w3.org/2000/svg">
                        <rect width="100%" height="10" x="0" y="0"/>
                    </svg>""".encode('utf-16')
        self.engine.convert_svg_to_png(buffer)
        expect(self.engine.extension).to_equal('.png')

    @mock.patch('thumbor.engines.cairosvg', new=None)
    @mock.patch('thumbor.engines.logger.error')
    def test_not_imported_cairosvg_failed_to_convert_svg_to_png(self, mockLogError):
        buffer = """<svg width="10px" height="20px" viewBox="0 0 10 20"
                    xmlns="http://www.w3.org/2000/svg">
                        <rect width="100%" height="10" x="0" y="0"/>
                    </svg>"""
        returned_buffer = self.engine.convert_svg_to_png(buffer)
        expect(mockLogError.called).to_be_true()
        expect(buffer).to_equal(returned_buffer)

    def test_can_identify_msb_tiff(self):
        with open(join(STORAGE_PATH, 'gradient_msb_16bperchannel.tif'), 'r') as im:
            buffer = im.read()
        mime = self.engine.get_mimetype(buffer)
#.........这里部分代码省略.........
开发者ID:caeugusmao,项目名称:thumbor,代码行数:103,代码来源:test_base_engine.py

示例2: BaseEngineTestCase

# 需要导入模块: from thumbor.engines import BaseEngine [as 别名]
# 或者: from thumbor.engines.BaseEngine import convert_svg_to_png [as 别名]
class BaseEngineTestCase(TestCase):

    def get_context(self):
        cfg = Config(
            SECURITY_KEY='ACME-SEC',
            ENGINE='thumbor.engines',
        )
        cfg.STORAGE = 'thumbor.storages.no_storage'

        return Context(config=cfg)

    def flip_horizontally(self):
        ((a, b), (c, d)) = self.image
        self.image = (
            (b, a),
            (d, c)
        )

    def flip_vertically(self):
        ((a, b), (c, d)) = self.image
        self.image = (
            (c, d),
            (a, b)
        )

    def rotate(self, value):
        ((a, b), (c, d)) = self.image
        if value == 270:
            self.image = (
                (c, a),
                (d, b)
            )
        elif value == 180:
            self.image = (
                (d, c),
                (b, a)
            )
        elif value == 90:
            self.image = (
                (b, d),
                (a, c)
            )

    def setUp(self):
        self.image = (
            (1, 2),
            (3, 4)
        )
        self.context = self.get_context()
        self.engine = BaseEngine(self.context)
        self.engine.flip_horizontally = mock.MagicMock()
        self.engine.flip_horizontally.side_effect = self.flip_horizontally
        self.engine.flip_vertically = mock.MagicMock()
        self.engine.flip_vertically.side_effect = self.flip_vertically
        self.engine.rotate = mock.MagicMock()
        self.engine.rotate.side_effect = self.rotate

    def test_create_engine(self):
        expect(self.engine).to_be_instance_of(BaseEngine)

    def test_convert_svg_to_png(self):
        buffer = """<svg width="10px" height="20px" viewBox="0 0 10 20"
                    xmlns="http://www.w3.org/2000/svg">
                        <rect width="100%" height="10" x="0" y="0"/>
                    </svg>"""
        self.engine.convert_svg_to_png(buffer)
        expect(self.engine.extension).to_equal('.png')

    def test_convert_svg_with_xml_preamble_to_png(self):
        buffer = """<?xml version="1.0" encoding="utf-8"?>
                    <svg width="10px" height="20px" viewBox="0 0 10 20"
                    xmlns="http://www.w3.org/2000/svg">
                        <rect width="100%" height="10" x="0" y="0"/>
                    </svg>""".encode('utf-8')
        self.engine.convert_svg_to_png(buffer)
        expect(self.engine.extension).to_equal('.png')

    def test_convert_svg_utf16_to_png(self):
        buffer = """<?xml version="1.0" encoding="utf-16"?>
                    <svg width="10px" height="20px" viewBox="0 0 10 20"
                    xmlns="http://www.w3.org/2000/svg">
                        <rect width="100%" height="10" x="0" y="0"/>
                    </svg>""".encode('utf-16')
        self.engine.convert_svg_to_png(buffer)
        expect(self.engine.extension).to_equal('.png')

    @mock.patch('thumbor.engines.cairosvg', new=None)
    @mock.patch('thumbor.engines.logger.error')
    def test_not_imported_cairosvg_failed_to_convert_svg_to_png(self, mockLogError):
        buffer = """<svg width="10px" height="20px" viewBox="0 0 10 20"
                    xmlns="http://www.w3.org/2000/svg">
                        <rect width="100%" height="10" x="0" y="0"/>
                    </svg>"""
        returned_buffer = self.engine.convert_svg_to_png(buffer)
        expect(mockLogError.called).to_be_true()
        expect(buffer).to_equal(returned_buffer)

    def test_get_orientation(self):
        self.engine.exif = exif_str(1)
        expect(self.engine.get_orientation()).to_equal(1)
#.........这里部分代码省略.........
开发者ID:5um1th,项目名称:thumbor,代码行数:103,代码来源:test_base_engine.py


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