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


Python Engine.get_image方法代码示例

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


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

示例1: test_landscape_crop

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def test_landscape_crop(self):

        def mean_pixel(x, y):
            values = im.getpixel((x, y))
            if not isinstance(values, (tuple, list)):
                values = [values]
            return sum(values) / len(values)

        for crop in ('center', '50% 200%', '50px 700px'):
            th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            self.assertEqual(mean_pixel(0, 50), 255)
            self.assertEqual(mean_pixel(45, 50), 255)
            self.assertEqual(250 < mean_pixel(49, 50) <= 255, True)
            self.assertEqual(mean_pixel(55, 50), 0)
            self.assertEqual(mean_pixel(99, 50), 0)

        for crop in ('left', '0%', '0px'):
            th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            for x in range(0, 99, 10):
                for y in range(0, 99, 10):
                    self.assertEqual(250 < mean_pixel(x, y) <= 255, True)

        for crop in ('right', '100%', '100px'):
            th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            for x in range(0, 99, 10):
                for y in range(0, 99, 10):
                    self.assertEqual(0 <= mean_pixel(x, y) < 5, True)
开发者ID:aalebedev,项目名称:sorl-thumbnail,代码行数:35,代码来源:tests.py

示例2: testLandscapeCrop

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def testLandscapeCrop(self):
        def mean_pixel(x, y):
            values = im.getpixel((x, y))
            if not isinstance(values, (tuple, list)):
                values = [values]
            return reduce(operator.add, values) / len(values)

        for crop in ("center", "50% 200%", "50px 700px"):
            th = self.backend.get_thumbnail(self.landscape, "100x100", crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            self.assertEqual(mean_pixel(0, 50), 255)
            self.assertEqual(mean_pixel(45, 50), 255)
            self.assertEqual(250 < mean_pixel(49, 50) <= 255, True)
            self.assertEqual(mean_pixel(55, 50), 0)
            self.assertEqual(mean_pixel(99, 50), 0)
        for crop in ("left", "0%", "0px"):
            th = self.backend.get_thumbnail(self.landscape, "100x100", crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            for x in xrange(0, 99, 10):
                for y in xrange(0, 99, 10):
                    self.assertEqual(250 < mean_pixel(x, y) <= 255, True)
        for crop in ("right", "100%", "100px"):
            th = self.backend.get_thumbnail(self.landscape, "100x100", crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            for x in xrange(0, 99, 10):
                for y in xrange(0, 99, 10):
                    self.assertEqual(0 <= mean_pixel(x, y) < 5, True)
开发者ID:hvdklauw,项目名称:sorl-thumbnail,代码行数:32,代码来源:tests.py

示例3: test_portrait_crop

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def test_portrait_crop(self):
        def mean_pixel(x, y):
            values = im.getpixel((x, y))
            if not isinstance(values, (tuple, list)):
                values = [values]
            return sum(values) / len(values)

        for crop in ('center', '88% 50%', '50px'):
            th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            self.assertEqual(mean_pixel(50, 0), 255)
            self.assertEqual(mean_pixel(50, 45), 255)
            self.assertEqual(250 <= mean_pixel(50, 49) <= 255, True, mean_pixel(50, 49))
            self.assertEqual(mean_pixel(50, 55), 0)
            self.assertEqual(mean_pixel(50, 99), 0)

        for crop in ('top', '0%', '0px'):
            th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            for x in range(0, 99, 10):
                for y in range(0, 99, 10):
                    self.assertEqual(250 < mean_pixel(x, y) <= 255, True)

        for crop in ('bottom', '100%', '100px'):
            th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            for x in range(0, 99, 10):
                for y in range(0, 99, 10):
                    self.assertEqual(0 <= mean_pixel(x, y) < 5, True)
开发者ID:aalebedev,项目名称:sorl-thumbnail,代码行数:34,代码来源:tests.py

示例4: testPortraitCrop

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def testPortraitCrop(self):
        def mean_pixel(x, y):
            values = im.getpixel((x, y))
            if not isinstance(values, (tuple, list)):
                values = [values]
            return reduce(operator.add, values) / len(values)

        for crop in ("center", "88% 50%", "50px"):
            th = self.backend.get_thumbnail(self.portrait, "100x100", crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            self.assertEqual(mean_pixel(50, 0), 255)
            self.assertEqual(mean_pixel(50, 45), 255)
            self.assertEqual(250 < mean_pixel(50, 49) <= 255, True)
            self.assertEqual(mean_pixel(50, 55), 0)
            self.assertEqual(mean_pixel(50, 99), 0)
        for crop in ("top", "0%", "0px"):
            th = self.backend.get_thumbnail(self.portrait, "100x100", crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            for x in xrange(0, 99, 10):
                for y in xrange(0, 99, 10):
                    self.assertEqual(250 < mean_pixel(x, y) <= 255, True)
        for crop in ("bottom", "100%", "100px"):
            th = self.backend.get_thumbnail(self.portrait, "100x100", crop=crop)
            engine = PILEngine()
            im = engine.get_image(th)
            for x in xrange(0, 99, 10):
                for y in xrange(0, 99, 10):
                    self.assertEqual(0 <= mean_pixel(x, y) < 5, True)
开发者ID:hvdklauw,项目名称:sorl-thumbnail,代码行数:32,代码来源:tests.py

示例5: test_retina

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def test_retina(self):
        get_thumbnail(self.im, '50x50')

        actions = [
            # save regular resolution, same as in StorageTestCase
            'open: retina.jpg',
            'save: test/cache/19/10/1910dc350bbe9ee55fd9d8d3d5e38e19.jpg',
            'get_available_name: test/cache/19/10/1910dc350bbe9ee55fd9d8d3d5e38e19.jpg',
            'exists: test/cache/19/10/1910dc350bbe9ee55fd9d8d3d5e38e19.jpg',

            # save the 1.5x resolution version
            'save: test/cache/19/10/[email protected]',
            'get_available_name: test/cache/19/10/1910dc[email protected]',
            'exists: test/cache/19/10/[email protected]',

            # save the 2x resolution version
            'save: test/cache/19/10/[email protected]',
            'get_available_name: test/cache/19/10/[email protected]',
            'exists: test/cache/19/10/[email protected]'
        ]
        self.assertEqual(self.log, actions)

        with open(pjoin(settings.MEDIA_ROOT, 'test/cache/19/10/[email protected]')) as fp:
            engine = PILEngine()
            self.assertEqual(engine.get_image_size(engine.get_image(ImageFile(file_=fp))), (75, 75))
开发者ID:aalebedev,项目名称:sorl-thumbnail,代码行数:27,代码来源:tests.py

示例6: test_orientation

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def test_orientation(self):
        ref = Image.open(pjoin(DATA_DIR, '1_topleft.jpg'))
        top = ref.getpixel((14, 7))
        left = ref.getpixel((7, 14))
        engine = PILEngine()

        def epsilon(x, y):
            if isinstance(x, (tuple, list)):
                x = sum(x) / len(x)
            if isinstance(y, (tuple, list)):
                y = sum(y) / len(y)
            return abs(x - y)

        data_images = (
            '1_topleft.jpg',
            '2_topright.jpg',
            '3_bottomright.jpg',
            '4_bottomleft.jpg',
            '5_lefttop.jpg',
            '6_righttop.jpg',
            '7_rightbottom.jpg',
            '8_leftbottom.jpg'
        )

        for name in data_images:
            th = self.backend.get_thumbnail('data/%s' % name, '30x30')
            im = engine.get_image(th)

            self.assertLess(epsilon(top, im.getpixel((14, 7))), 10)
            self.assertLess(epsilon(left, im.getpixel((7, 14))), 10)
            exif = im._getexif()

            if exif:
                self.assertEqual(exif.get(0x0112), 1)
开发者ID:kindbeetle,项目名称:sorl-thumbnail,代码行数:36,代码来源:tests.py

示例7: test_retina

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def test_retina(self):
        get_thumbnail(self.image, '50x50')

        actions = [
            'exists: test/cache/91/bb/91bb06cf9169e4c52132bb113f2d4c0d.jpg',

            # save regular resolution, same as in StorageTestCase
            'open: retina.jpg',
            'save: test/cache/91/bb/91bb06cf9169e4c52132bb113f2d4c0d.jpg',
            'get_available_name: test/cache/91/bb/91bb06cf9169e4c52132bb113f2d4c0d.jpg',
            'exists: test/cache/91/bb/91bb06cf9169e4c52132bb113f2d4c0d.jpg',

            # save the 1.5x resolution version
            'save: test/cache/91/bb/[email protected]',
            'get_available_name: test/cache/91/bb/[email protected]',
            'exists: test/cache/91/bb/[email protected]',

            # save the 2x resolution version
            'save: test/cache/91/bb/[email protected]',
            'get_available_name: test/cache/91/bb/[email protected]',
            'exists: test/cache/91/bb/[email protected]'
        ]
        self.assertEqual(self.log, actions)

        path = os.path.join(settings.MEDIA_ROOT,
                            'test/cache/91/bb/[email protected]')

        with open(path) as fp:
            engine = PILEngine()
            self.assertEqual(engine.get_image_size(engine.get_image(ImageFile(file_=fp))), (75, 75))
开发者ID:DeadWisdom,项目名称:sorl-thumbnail,代码行数:32,代码来源:test_alternative_resolutions.py

示例8: _clean_image

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def _clean_image(self):
        from sorl.thumbnail.engines.pil_engine import Engine
        from sorl.thumbnail.images import ImageFile

        e = Engine()
        f = ImageFile(self.image.file)
        tmp_image = e.get_image(f)
        tmp_image = e._orientation(tmp_image)
        new_file = StringIO()
        tmp_image.save(new_file, 'jpeg')
        file_content = ContentFile(new_file.getvalue())
        self.image.save(self.image.name, file_content, save=False)
开发者ID:Bjwebb,项目名称:electionleaflets,代码行数:14,代码来源:models.py

示例9: test_crop_image_with_icc_profile

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def test_crop_image_with_icc_profile(self):
        name = 'data/icc_profile_test.jpg'
        item, _ = Item.objects.get_or_create(image=name)

        im = ImageFile(item.image)
        th = self.BACKEND.get_thumbnail(im, '100x100')

        engine = PILEngine()

        self.assertEqual(
            engine.get_image(im).info.get('icc_profile'),
            engine.get_image(th).info.get('icc_profile')
        )
开发者ID:DeadWisdom,项目名称:sorl-thumbnail,代码行数:15,代码来源:test_engines.py

示例10: test_orientation

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
 def test_orientation(self):
     data_dir = pjoin(settings.MEDIA_ROOT, 'data')
     shutil.copytree(settings.DATA_ROOT, data_dir)
     ref = Image.open(pjoin(data_dir, '1_topleft.jpg'))
     top = ref.getpixel((14, 7))
     left = ref.getpixel((7, 14))
     engine = PILEngine()
     def epsilon(x, y):
         if isinstance(x, (tuple, list)):
             x = sum(x) / len(x)
         if isinstance(y, (tuple, list)):
             y = sum(y) / len(y)
         return abs(x - y)
     for name in sorted(os.listdir(data_dir)):
         th = self.backend.get_thumbnail('data/%s' % name, '30x30')
         im = engine.get_image(th)
         self.assertLess(epsilon(top, im.getpixel((14, 7))), 10)
         self.assertLess(epsilon(left, im.getpixel((7, 14))), 10)
         exif = im._getexif()
         if exif:
             self.assertEqual(exif.get(0x0112), 1)
开发者ID:bettlebrox,项目名称:sorl-thumbnail,代码行数:23,代码来源:tests.py

示例11: test_orientation

# 需要导入模块: from sorl.thumbnail.engines.pil_engine import Engine [as 别名]
# 或者: from sorl.thumbnail.engines.pil_engine.Engine import get_image [as 别名]
    def test_orientation(self):
        ref = Image.open(os.path.join(DATA_DIR, '1_topleft.jpg'))
        top = ref.getpixel((14, 7))
        left = ref.getpixel((7, 14))
        engine = PILEngine()

        def epsilon(x, y):
            if isinstance(x, (tuple, list)):
                x = sum(x) / len(x)
            if isinstance(y, (tuple, list)):
                y = sum(y) / len(y)
            return abs(x - y)

        data_images = (
            '1_topleft.jpg',
            '2_topright.jpg',
            '3_bottomright.jpg',
            '4_bottomleft.jpg',
            '5_lefttop.jpg',
            '6_righttop.jpg',
            '7_rightbottom.jpg',
            '8_leftbottom.jpg'
        )

        for name in data_images:
            th = self.BACKEND.get_thumbnail('data/%s' % name, '30x30')
            im = engine.get_image(th)

            self.assertLess(epsilon(top, im.getpixel((14, 7))), 10)
            self.assertLess(epsilon(left, im.getpixel((7, 14))), 10)
            exif = im._getexif()

            # no exif editor in GraphicsMagick
            if exif and not (settings.THUMBNAIL_CONVERT.endswith('gm convert') or
                             'pgmagick_engine' in settings.THUMBNAIL_ENGINE):
                self.assertEqual(exif.get(0x0112), 1)
开发者ID:mariocesar,项目名称:sorl-thumbnail,代码行数:38,代码来源:test_templatetags.py


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