• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pil.Engine类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_load_image_with_metadata

    def test_load_image_with_metadata(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'Christophe_Henner_-_June_2016.jpg'), 'r') as im:
            buffer = im.read()

        engine.load(buffer, None)
        image = engine.image
        expect(image.format).to_equal('JPEG')
        expect(engine.metadata).Not.to_be_null()
        expect(engine.metadata.__class__.__name__).to_equal('ImageMetadata')

        # read the xmp tags
        xmp_keys = engine.metadata.xmp_keys
        expect(len(xmp_keys)).to_equal(44)
        expect('Xmp.aux.LensSerialNumber' in xmp_keys).to_be_true()

        width = engine.metadata[b'Xmp.aux.LensSerialNumber'].value
        expect(width).to_equal('0000c139be')

        # read EXIF tags
        exif_keys = engine.metadata.exif_keys
        expect(len(exif_keys)).to_equal(37)
        expect('Exif.Image.Software' in exif_keys).to_be_true()
        expect(engine.metadata[b'Exif.Image.Software'].value).to_equal('Adobe Photoshop Lightroom 4.4 (Macintosh)')

        # read IPTC tags
        iptc_keys = engine.metadata.iptc_keys
        expect(len(iptc_keys)).to_equal(6)
        expect('Iptc.Application2.DateCreated' in iptc_keys).to_be_true()
        expect(engine.metadata[b'Iptc.Application2.DateCreated'].value).to_equal(
            [datetime.date(2016, 6, 23)]
        )
开发者ID:RealGeeks,项目名称:thumbor,代码行数:32,代码来源:test_pil.py


示例2: test_convert_tif_16bit_per_channel_lsb_to_png

 def test_convert_tif_16bit_per_channel_lsb_to_png(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, 'gradient_lsb_16bperchannel.tif'), 'r') as im:
         buffer = im.read()
     expect(buffer).not_to_equal(None)
     engine.convert_tif_to_png(buffer)
     expect(engine.extension).to_equal('.png')
开发者ID:RealGeeks,项目名称:thumbor,代码行数:7,代码来源:test_pil.py


示例3: test_load_image_with_metadata

    def test_load_image_with_metadata(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'BlueSquare.jpg'), 'r') as im:
            buffer = im.read()

        engine.load(buffer, None)
        image = engine.image
        expect(image.format).to_equal('JPEG')
        expect(engine.metadata).Not.to_be_null()
        expect(engine.metadata.__class__.__name__).to_equal('ImageMetadata')

        # read the xmp tags
        xmp_keys = engine.metadata.xmp_keys
        expect(len(xmp_keys)).to_equal(27)
        expect('Xmp.tiff.ImageWidth' in xmp_keys).to_be_true()

        width = engine.metadata[b'Xmp.tiff.ImageWidth'].value
        expect(width).to_equal(360)

        # read EXIF tags
        exif_keys = engine.metadata.exif_keys
        expect(len(exif_keys)).to_equal(17)
        expect('Exif.Image.Orientation' in exif_keys).to_be_true()
        expect(engine.metadata[b'Exif.Image.Orientation'].value).to_equal(1)

        # read IPTC tags
        iptc_keys = engine.metadata.iptc_keys
        expect(len(iptc_keys)).to_equal(4)
        expect('Iptc.Application2.Keywords' in iptc_keys).to_be_true()
        expect(engine.metadata[b'Iptc.Application2.Keywords'].value).to_equal(
            ['XMP', 'Blue Square', 'test file', 'Photoshop', '.jpg']
        )
开发者ID:abaldwin1,项目名称:thumbor,代码行数:32,代码来源:test_pil.py


示例4: test_should_be_ok_but_150x150

 def test_should_be_ok_but_150x150(self):
     response = self.fetch('/unsafe/200x200/grayscale.jpg')
     engine = Engine(self.context)
     engine.load(response.body, '.jpg')
     expect(response.code).to_equal(200)
     expect(response.headers['Content-Type']).to_equal('image/jpeg')
     expect(engine.size).to_equal((150, 150))
开发者ID:scorphus,项目名称:thumbor,代码行数:7,代码来源:test_base_handler.py


示例5: test_not_imported_cv2_failed_to_convert_tif_to_png

 def test_not_imported_cv2_failed_to_convert_tif_to_png(self, mockLogError):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, 'gradient_8bit.tif'), 'r') as im:
         buffer = im.read()
     returned_buffer = engine.convert_tif_to_png(buffer)
     expect(mockLogError.called).to_be_true()
     expect(buffer).to_equal(returned_buffer)
开发者ID:RealGeeks,项目名称:thumbor,代码行数:7,代码来源:test_pil.py


示例6: test_can_read_image_svg_with_px_units_and_convert_png

    def test_can_read_image_svg_with_px_units_and_convert_png(self):
        response = self.fetch('/unsafe/escudo.svg')
        expect(response.code).to_equal(200)
        expect(response.body).to_be_png()

        engine = Engine(self.context)
        engine.load(response.body, '.png')
        expect(engine.size).to_equal((1080, 1080))
开发者ID:evgeny-popov,项目名称:thumbor,代码行数:8,代码来源:test_base_handler.py


示例7: test_can_read_image_svg_with_inch_units_and_convert_png

    def test_can_read_image_svg_with_inch_units_and_convert_png(self):
        response = self.fetch('/unsafe/Commons-logo-inches.svg')
        expect(response.code).to_equal(200)
        expect(response.body).to_be_png()

        engine = Engine(self.context)
        engine.load(response.body, '.png')
        expect(engine.size).to_equal((2000, 2600))
开发者ID:scorphus,项目名称:thumbor,代码行数:8,代码来源:test_base_handler.py


示例8: test_load_tif_8bit_per_channel

    def test_load_tif_8bit_per_channel(self):
        engine = Engine(self.context)
        with open(join(STORAGE_PATH, 'gradient_8bit.tif'), 'r') as im:
            buffer = im.read()
        expect(buffer).not_to_equal(None)
        engine.load(buffer, None)

        final_bytes = BytesIO(engine.read())
        im = Image.open(final_bytes)
        expect(im.format).to_equal('PNG')
        expect(im.size).to_equal((100, 100))
开发者ID:caeugusmao,项目名称:thumbor,代码行数:11,代码来源:test_pil.py


示例9: GetImageWithAutoWebP

class GetImageWithAutoWebP(BaseContext):
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.AUTO_WEBP = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application

    def topic(self):
        return self.get('/unsafe/image.jpg', headers={
            "Accept": 'image/webp,*/*;q=0.8'
        })

    def should_be_webp(self, response):
        expect(response.code).to_equal(200)
        expect(response.headers).to_include('Vary')
        expect(response.headers['Vary']).to_include('Accept')

        image = self.engine.create_image(response.body)
        expect(image.format.lower()).to_equal('webp')
开发者ID:runa,项目名称:thumbor,代码行数:30,代码来源:handler_images_vows.py


示例10: test_can_set_resampling_filter

    def test_can_set_resampling_filter(self):
        to_test = {
            "LANCZOS": Image.LANCZOS,
            "NEAREST": Image.NEAREST,
            "BiLinear": Image.BILINEAR,
            "bicubic": Image.BICUBIC,
            "garbage": Image.LANCZOS,
        }

        if hasattr(Image, "HAMMING"):
            to_test["HAMMING"] = Image.HAMMING

        for setting, expected in to_test.items():
            cfg = Config(PILLOW_RESAMPLING_FILTER=setting)
            engine = Engine(Context(config=cfg))
            expect(engine.get_resize_filter()).to_equal(expected)

        cfg = Config()
        engine = Engine(Context(config=cfg))
        expect(engine.get_resize_filter()).to_equal(Image.LANCZOS)
开发者ID:thumbor,项目名称:thumbor,代码行数:20,代码来源:test_pil.py


示例11: test_convert_png_1bit_to_png

 def test_convert_png_1bit_to_png(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, '1bit.png'), 'r') as im:
         buffer = im.read()
     engine.load(buffer, '.png')
     engine.resize(10, 10)
     mode, _ = engine.image_data_as_rgb()
     expect(mode).to_equal('P')  # Note that this is not a true 1bit image, it's 8bit in black/white.
开发者ID:scorphus,项目名称:thumbor,代码行数:8,代码来源:test_pil.py


示例12: test_convert_should_preserve_palette_mode

 def test_convert_should_preserve_palette_mode(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, '256_color_palette.png'), 'r') as im:
         buffer = im.read()
     engine.load(buffer, '.png')
     engine.resize(10, 10)
     mode, _ = engine.image_data_as_rgb()
     expect(mode).to_equal('P')
开发者ID:scorphus,项目名称:thumbor,代码行数:8,代码来源:test_pil.py


示例13: test_convert_png_1bit_to_png

 def test_convert_png_1bit_to_png(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, '1bit.png'), 'r') as im:
         buffer = im.read()
     engine.load(buffer, '.png')
     engine.resize(10, 10)
     mode, _ = engine.image_data_as_rgb()
     expect(mode).to_equal('RGBA')
开发者ID:RealGeeks,项目名称:thumbor,代码行数:8,代码来源:test_pil.py


示例14: test_resize_truncated_image

 def test_resize_truncated_image(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, 'BlueSquare_truncated.jpg'), 'r') as im:
         buffer = im.read()
     engine.load(buffer, '.jpg')
     engine.resize(10, 10)
     mode, _ = engine.image_data_as_rgb()
     expect(mode).to_equal('RGB')
开发者ID:RealGeeks,项目名称:thumbor,代码行数:8,代码来源:test_pil.py


示例15: get_app

    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = storage_path
        cfg.AUTO_WEBP = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None)
        server.security_key = 'ACME-SEC'
        ctx = Context(server, cfg, importer)
        application = ThumborServiceApp(ctx)

        self.engine = PILEngine(ctx)

        return application
开发者ID:runa,项目名称:thumbor,代码行数:16,代码来源:handler_images_vows.py


示例16: test_should_preserve_png_transparency

    def test_should_preserve_png_transparency(self):
        engine = Engine(self.context)

        with open(join(STORAGE_PATH, 'paletted-transparent.png'), 'r') as im:
            buffer = im.read()

        engine.load(buffer, 'png')
        expect(engine.original_mode).to_equal('P')
        engine.resize(200, 150)

        img = Image.open(BytesIO(engine.read('.png')))

        expect(img.mode).to_equal('P')
        expect(img.format.lower()).to_equal('png')

        transparent_pixels_count = sum(img.convert('RGBA')
                                       .split()[3]  # Get alpha channel
                                       .point(lambda x: 0 if x else 1)  # return 1 if pixel is transparent, 0 otherwise
                                       .getdata())

        # Image has total of 200x150=30000 pixels. Most of them should be transparent
        expect(transparent_pixels_count).to_be_greater_than(19000)
开发者ID:caeugusmao,项目名称:thumbor,代码行数:22,代码来源:test_pil.py


示例17: test_should_be_ok_without_orientation_exif

 def test_should_be_ok_without_orientation_exif(self):
     response = self.fetch('/unsafe/20x20.jpg')
     expect(response.code).to_equal(200)
     engine = Engine(self.context)
     engine.load(response.body, '.jpg')
     expect(engine.size).to_equal((20, 20))
开发者ID:scorphus,项目名称:thumbor,代码行数:6,代码来源:test_base_handler.py


示例18: test_should_be_ok_when_orientation_exif

 def test_should_be_ok_when_orientation_exif(self):
     response = self.fetch('/unsafe/10_years_of_Wikipedia_by_Guillaume_Paumier.jpg')
     expect(response.code).to_equal(200)
     engine = Engine(self.context)
     engine.load(response.body, '.jpg')
     expect(engine.size).to_equal((4052, 3456))
开发者ID:scorphus,项目名称:thumbor,代码行数:6,代码来源:test_base_handler.py


示例19: test_load_image

 def test_load_image(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, 'image.jpg'), 'r') as im:
         buffer = im.read()
     image = engine.create_image(buffer)
     expect(image.format).to_equal('JPEG')
开发者ID:RealGeeks,项目名称:thumbor,代码行数:6,代码来源:test_pil.py


示例20: test_convert_tif_8bit_per_channel_to_png

 def test_convert_tif_8bit_per_channel_to_png(self):
     engine = Engine(self.context)
     with open(join(STORAGE_PATH, "gradient_8bit.tif"), "r") as im:
         buffer = im.read()
     engine.convert_tif_to_png(buffer)
     expect(engine.extension).to_equal(".png")
开发者ID:thumbor,项目名称:thumbor,代码行数:6,代码来源:test_pil.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python importer.Importer类代码示例发布时间:2022-05-27
下一篇:
Python engines.BaseEngine类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap