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


Python ImageFile.LOAD_TRUNCATED_IMAGES属性代码示例

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


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

示例1: test_verify_ignores_crc_error

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def test_verify_ignores_crc_error(self):
        # check ignores crc errors in ancillary chunks

        chunk_data = chunk(b'tEXt', b'spam')
        broken_crc_chunk_data = chunk_data[:-1] + b'q'  # break CRC

        image_data = HEAD + broken_crc_chunk_data + TAIL
        self.assertRaises(SyntaxError, PngImagePlugin.PngImageFile,
                          BytesIO(image_data))

        ImageFile.LOAD_TRUNCATED_IMAGES = True
        try:
            im = load(image_data)
            self.assertIsNotNone(im)
        finally:
            ImageFile.LOAD_TRUNCATED_IMAGES = False 
开发者ID:holzschu,项目名称:python3_ios,代码行数:18,代码来源:test_file_png.py

示例2: test_leak_load

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def test_leak_load(self):
        with open('Tests/images/hopper.png', 'rb') as f:
            DATA = BytesIO(f.read(16 * 1024))

        ImageFile.LOAD_TRUNCATED_IMAGES = True
        with Image.open(DATA) as im:
            im.load()

        def core():
            with Image.open(DATA) as im:
                im.load()

        try:
            self._test_leak(core)
        finally:
            ImageFile.LOAD_TRUNCATED_IMAGES = False 
开发者ID:holzschu,项目名称:python3_ios,代码行数:18,代码来源:test_file_png.py

示例3: get_image_obj

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def get_image_obj(src_file, new_file):
    """Gets an image object and png flag."""
    output = None
    png = False
    if src_file.lower().endswith('.png'):
        png = True
    if src_file == new_file:
        return None, None
    if not os.path.exists(src_file):
        raise RuntimeError('Cannot find ' + src_file)
    ImageFile.LOAD_TRUNCATED_IMAGES = True
    try:
        im = Image.open(src_file)
        im.LOAD_TRUNCATED_IMAGES = True
    except:
        print('Cannot use as image: ' + src_file)
        im = None
    if im is None:
        return None, None
    return im, png 
开发者ID:ekansa,项目名称:open-context-py,代码行数:22,代码来源:media.py

示例4: test_truncated_jpeg_should_read_all_the_data

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def test_truncated_jpeg_should_read_all_the_data(self):
        filename = "Tests/images/truncated_jpeg.jpg"
        ImageFile.LOAD_TRUNCATED_IMAGES = True
        im = Image.open(filename)
        im.load()
        ImageFile.LOAD_TRUNCATED_IMAGES = False
        self.assertIsNotNone(im.getbbox()) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:9,代码来源:test_file_jpeg.py

示例5: test_truncated_without_errors

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def test_truncated_without_errors(self):
        if "zip_encoder" not in codecs:
            self.skipTest("PNG (zlib) encoder not available")

        im = Image.open("Tests/images/truncated_image.png")

        ImageFile.LOAD_TRUNCATED_IMAGES = True
        try:
            im.load()
        finally:
            ImageFile.LOAD_TRUNCATED_IMAGES = False 
开发者ID:holzschu,项目名称:python3_ios,代码行数:13,代码来源:test_imagefile.py

示例6: test_broken_datastream_without_errors

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def test_broken_datastream_without_errors(self):
        if "zip_encoder" not in codecs:
            self.skipTest("PNG (zlib) encoder not available")

        im = Image.open("Tests/images/broken_data_stream.png")

        ImageFile.LOAD_TRUNCATED_IMAGES = True
        try:
            im.load()
        finally:
            ImageFile.LOAD_TRUNCATED_IMAGES = False 
开发者ID:holzschu,项目名称:python3_ios,代码行数:13,代码来源:test_imagefile.py

示例7: test_verify_not_ignores_crc_error_in_required_chunk

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def test_verify_not_ignores_crc_error_in_required_chunk(self):
        # check does not ignore crc errors in required chunks

        image_data = MAGIC + IHDR[:-1] + b'q' + TAIL

        ImageFile.LOAD_TRUNCATED_IMAGES = True
        try:
            self.assertRaises(SyntaxError, PngImagePlugin.PngImageFile,
                              BytesIO(image_data))
        finally:
            ImageFile.LOAD_TRUNCATED_IMAGES = False 
开发者ID:holzschu,项目名称:python3_ios,代码行数:13,代码来源:test_file_png.py

示例8: test_ignore_dos_text

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def test_ignore_dos_text(self):
        ImageFile.LOAD_TRUNCATED_IMAGES = True

        try:
            im = Image.open(TEST_FILE)
            im.load()
        finally:
            ImageFile.LOAD_TRUNCATED_IMAGES = False

        for s in im.text.values():
            self.assertLess(len(s), 1024*1024, "Text chunk larger than 1M")

        for s in im.info.values():
            self.assertLess(len(s), 1024*1024, "Text chunk larger than 1M") 
开发者ID:holzschu,项目名称:python3_ios,代码行数:16,代码来源:check_png_dos.py

示例9: ready

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def ready(self):
        super(CourseMetadataConfig, self).ready()
        # We need to add this setting because, since MM programs we are accepting banner
        # images with height less than 480 max. In order to accept those images, we need
        # to allow PIL to work with these images correctly by setting this variable true
        ImageFile.LOAD_TRUNCATED_IMAGES = True
        # noinspection PyUnresolvedReferences
        import course_discovery.apps.course_metadata.signals  # pylint: disable=import-outside-toplevel,unused-import 
开发者ID:edx,项目名称:course-discovery,代码行数:10,代码来源:apps.py

示例10: run_filter

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def run_filter(image, f_a, filt):
    try:
        g = f_a.filter(filt)
    except IOError as e:
        # Generically print it, then try again (truncated error)
        logger.error("%s", e)
        ImageFile.LOAD_TRUNCATED_IMAGES = True
        g = f_a.filter(filt)

    g.save(os.path.join(image.veritas.results_directory, os.path.basename(image.veritas.file_name) + "_" + filt.name.replace(" ","_") + ".png")) 
开发者ID:bannsec,项目名称:stegoVeritas,代码行数:12,代码来源:filters.py

示例11: read_rgb_np

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def read_rgb_np(rgb_path):
    ImageFile.LOAD_TRUNCATED_IMAGES = True
    img = Image.open(rgb_path).convert('RGB')
    img = np.array(img,np.uint8)
    return img 
开发者ID:zju3dv,项目名称:pvnet-rendering,代码行数:7,代码来源:fuse.py

示例12: make_preview_file

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def make_preview_file(self, src_file, new_file):
        """ Makes preview images. This preserves the orginal
            aspect ratio. The height can be greater than the width,
            so we're not just going to use the thumbnail
            method
        """
        output = False
        png = False
        if '.png' in src_file or '.PNG' in src_file:
            png = True
        if src_file != new_file:
            if os.path.exists(src_file):
                # print('Getting: ' + src_file)
                ImageFile.LOAD_TRUNCATED_IMAGES = True
                try:
                    im = Image.open(src_file)
                    im.LOAD_TRUNCATED_IMAGES = True
                except:
                    print('Cannot use as image: ' + src_file)
                    im = False
                if im is not False:
                    ratio = 1  # default to same size
                    if im.width > self.preview_width:
                        new_width = self.preview_width
                        ratio = im.width / self.preview_width
                    else:
                        new_width = im.width
                    new_neight = int(round((im.height * ratio), 0))
                    size = (new_width, new_neight)
                    rescale_ok = False
                    try:
                        im.load()
                        rescale_ok = True
                    except IOError:
                        rescale_ok = False
                        print('Problem rescaling image for: ' + new_file)
                        self.errors.append(new_file)
                    if rescale_ok:
                        if png:
                            im.thumbnail(size, Image.ANTIALIAS)
                            background = Image.new("RGB", im.size, (255, 255, 255))
                            try:
                                background.paste(im, mask=im.split()[3]) # 3 is the alpha channel
                                background.save(new_file, "JPEG", quality=100)
                                output = new_file
                            except:
                                png = False
                                print('cannot save the preview file: ' + new_file)
                            del background
                        if png is False:
                            im.thumbnail(size, Image.ANTIALIAS)
                            try:
                                im.save(new_file, "JPEG", quality=100)
                                output = new_file
                            except:
                                print('cannot save the preview file: ' + new_file)
                    del im
        return output 
开发者ID:ekansa,项目名称:open-context-py,代码行数:60,代码来源:images.py

示例13: make_thumbnail_file

# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import LOAD_TRUNCATED_IMAGES [as 别名]
def make_thumbnail_file(self, src_file, new_file):
        """ This makes a thumbnail file. It is a little more
            simple, since it uses the default thumbnail method,
            meaning it has a max height and a max width
        """
        output = False
        png = False
        if '.png' in src_file or '.PNG' in src_file:
            png = True
        if src_file != new_file:
            if os.path.exists(src_file):
                # print('Getting: ' + src_file)
                ImageFile.LOAD_TRUNCATED_IMAGES = True
                try:
                    im = Image.open(src_file)
                    im.LOAD_TRUNCATED_IMAGES = True
                except:
                    print('Cannot use as image: ' + src_file)
                    im = False
                if im is not False:
                    size = (self.thumbnail_width_height,
                            self.thumbnail_width_height)
                    rescale_ok = False
                    try:
                        im.load()
                        rescale_ok = True
                    except IOError:
                        rescale_ok = False
                        print('Problem rescaling image for: ' + new_file)
                        self.errors.append(new_file)
                    if rescale_ok:
                        if png:
                            im.thumbnail(size, Image.ANTIALIAS)
                            background = Image.new("RGB", im.size, (255, 255, 255))
                            try:
                                background.paste(im, mask=im.split()[3]) # 3 is the alpha channel
                                background.save(new_file, "JPEG", quality=100)
                                output = new_file
                            except:
                                png = False
                                print('cannot save the preview file: ' + new_file)
                            del background
                        if png is False:
                            im.thumbnail(size, Image.ANTIALIAS)
                            try:
                                im.save(new_file, "JPEG", quality=100)
                                output = new_file
                            except:
                                print('cannot save the preview file: ' + new_file)
                    del im
        return output 
开发者ID:ekansa,项目名称:open-context-py,代码行数:53,代码来源:images.py


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