本文整理汇总了Python中thumbor.engines.BaseEngine.reorientate方法的典型用法代码示例。如果您正苦于以下问题:Python BaseEngine.reorientate方法的具体用法?Python BaseEngine.reorientate怎么用?Python BaseEngine.reorientate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thumbor.engines.BaseEngine
的用法示例。
在下文中一共展示了BaseEngine.reorientate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseEngineTestCase
# 需要导入模块: from thumbor.engines import BaseEngine [as 别名]
# 或者: from thumbor.engines.BaseEngine import reorientate [as 别名]
#.........这里部分代码省略.........
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)
expect(self.engine.get_orientation()).to_equal(1)
self.engine.exif = exif_str(6)
expect(self.engine.get_orientation()).to_equal(6)
expect(self.engine.get_orientation()).to_equal(6)
self.engine.exif = exif_str(8)
expect(self.engine.get_orientation()).to_equal(8)
expect(self.engine.get_orientation()).to_equal(8)
def test_reorientate1(self):
# No rotation
self.engine.exif = exif_str(1)
self.engine.reorientate()
expect(self.engine.rotate.called).to_be_false()
expect(self.engine.flip_horizontally.called).to_be_false()
expect(self.engine.flip_vertically.called).to_be_false()
expect(self.image).to_equal(((1, 2), (3, 4)))
expect(self.engine.get_orientation()).to_equal(1)
def test_reorientate2(self):
self.image = (
(2, 1),
(4, 3)
)
# Flipped horizontally
self.engine.exif = exif_str(2)
self.engine.reorientate()
expect(self.engine.rotate.called).to_be_false()
expect(self.engine.flip_horizontally.called).to_be_true()
expect(self.engine.flip_vertically.called).to_be_false()
expect(self.image).to_equal(((1, 2), (3, 4)))
expect(self.engine.get_orientation()).to_equal(1)
def test_reorientate3(self):
# Rotated 180° Ⅎ
self.image = (
(4, 3),
(2, 1)
)
self.engine.exif = exif_str(3)
示例2: BaseEngineTestCase
# 需要导入模块: from thumbor.engines import BaseEngine [as 别名]
# 或者: from thumbor.engines.BaseEngine import reorientate [as 别名]
#.........这里部分代码省略.........
def test_convert_not_well_formed_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>""".encode('utf-8')
with expect.error_to_happen(ParseError):
self.engine.convert_svg_to_png(buffer)
expect(self.engine.extension).to_be_null()
def test_get_orientation_no_exif(self):
expect(hasattr(self.engine, 'exif')).to_be_false()
expect(self.engine.get_orientation()).to_be_null()
def test_get_orientation_null_exif(self):
self.engine.exif = None
expect(self.engine.get_orientation()).to_be_null()
def test_get_orientation_without_orientation_in_exif(self):
self.engine.exif = piexif.load(exif_str(1))
self.engine.exif['0th'].pop(piexif.ImageIFD.Orientation, None)
expect(self.engine.get_orientation()).to_be_null()
def test_get_orientation(self):
self.engine.exif = exif_str(1)
expect(self.engine.get_orientation()).to_equal(1)
expect(self.engine.get_orientation()).to_equal(1)
self.engine.exif = exif_str(6)
expect(self.engine.get_orientation()).to_equal(6)
expect(self.engine.get_orientation()).to_equal(6)
self.engine.exif = exif_str(8)
expect(self.engine.get_orientation()).to_equal(8)
expect(self.engine.get_orientation()).to_equal(8)
def test_reorientate_no_exif(self):
expect(hasattr(self.engine, 'exif')).to_be_false()
self.engine.reorientate()
expect(self.engine.get_orientation()).to_be_null()
def test_reorientate_null_exif(self):
self.engine.exif = None
self.engine.reorientate()
expect(self.engine.get_orientation()).to_be_null()
def test_reorientate1(self):
# No rotation
self.engine.exif = exif_str(1)
self.engine.reorientate()
expect(self.engine.rotate.called).to_be_false()
expect(self.engine.flip_horizontally.called).to_be_false()
expect(self.engine.flip_vertically.called).to_be_false()
expect(self.image).to_equal(((1, 2), (3, 4)))
expect(self.engine.get_orientation()).to_equal(1)
def test_reorientate2(self):
self.image = (
(2, 1),
(4, 3)
)
# Flipped horizontally
self.engine.exif = exif_str(2)
self.engine.reorientate()
expect(self.engine.rotate.called).to_be_false()
expect(self.engine.flip_horizontally.called).to_be_true()
expect(self.engine.flip_vertically.called).to_be_false()
expect(self.image).to_equal(((1, 2), (3, 4)))
示例3: BaseEngineTestCase
# 需要导入模块: from thumbor.engines import BaseEngine [as 别名]
# 或者: from thumbor.engines.BaseEngine import reorientate [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_get_orientation(self):
self.engine.exif = exif_str(1)
expect(self.engine.get_orientation()).to_equal(1)
expect(self.engine.get_orientation()).to_equal(1)
self.engine.exif = exif_str(6)
expect(self.engine.get_orientation()).to_equal(6)
expect(self.engine.get_orientation()).to_equal(6)
self.engine.exif = exif_str(8)
expect(self.engine.get_orientation()).to_equal(8)
expect(self.engine.get_orientation()).to_equal(8)
def test_reorientate1(self):
# No rotation
self.engine.exif = exif_str(1)
self.engine.reorientate()
expect(self.engine.rotate.called).to_be_false()
expect(self.engine.flip_horizontally.called).to_be_false()
expect(self.engine.flip_vertically.called).to_be_false()
expect(self.image).to_equal(((1, 2), (3, 4)))
expect(self.engine.get_orientation()).to_equal(1)
def test_reorientate2(self):
self.image = (
(2, 1),
(4, 3)
)
# Flipped horizontally
self.engine.exif = exif_str(2)
self.engine.reorientate()
expect(self.engine.rotate.called).to_be_false()
expect(self.engine.flip_horizontally.called).to_be_true()
expect(self.engine.flip_vertically.called).to_be_false()
expect(self.image).to_equal(((1, 2), (3, 4)))
expect(self.engine.get_orientation()).to_equal(1)
def test_reorientate3(self):
# Rotated 180° Ⅎ
self.image = (
#.........这里部分代码省略.........