當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。