def open(cls, fp): """ Open a PSD document. :param fp: filename or file-like object. :return: A :py:class:`~psd_tools.api.psd_image.PSDImage` object. """ if hasattr(fp, 'read'): self = cls(PSD.read(fp)) else: with open(fp, 'rb') as f: self = cls(PSD.read(f)) return self
def open(cls, fp, **kwargs): """ Open a PSD document. :param fp: filename or file-like object. :param encoding: charset encoding of the pascal string within the file, default 'macroman'. Some psd files need explicit encoding option. :return: A :py:class:`~psd_tools.api.psd_image.PSDImage` object. """ if hasattr(fp, 'read'): self = cls(PSD.read(fp, **kwargs)) else: with open(fp, 'rb') as f: self = cls(PSD.read(f, **kwargs)) return self
def test_psd_read_write(filename): basename = os.path.basename(filename) with open(filename, 'rb') as f: expected = f.read() with io.BytesIO(expected) as f: psd = PSD.read(f) padding = BAD_PADDINGS.get(basename, 4) with io.BytesIO() as f: psd.write(f, padding=padding) f.flush() output = f.getvalue() if basename in BAD_UNICODE_PADDINGS: pytest.xfail('Broken file') assert len(output) == len(expected) assert output == expected
def test_psd_write_read(filename): with open(filename, 'rb') as f: psd = PSD.read(f) check_write_read(psd) check_write_read(psd, encoding='utf_8')
def test_psd__iter_layers(filename, length): with open(os.path.join(TEST_ROOT, 'psd_files', filename), 'rb') as f: psd = PSD.read(f) assert len(list(psd._iter_layers())) == length