Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7729d88995 | ||
|
|
ea437d36ca | ||
|
|
93e688cc2b | ||
|
|
fbfa292204 | ||
|
|
8bcc652275 | ||
|
|
46baaaf2b2 | ||
|
|
2fa3738244 | ||
|
|
5a8e6b38a9 | ||
|
|
cd0dc67c23 | ||
|
|
fd005c6fa2 | ||
|
|
88dbf06820 |
11
PIL/Image.py
11
PIL/Image.py
@ -1620,13 +1620,17 @@ class Image(object):
|
||||
"""
|
||||
|
||||
filename = ""
|
||||
open_fp = False
|
||||
if isPath(fp):
|
||||
filename = fp
|
||||
open_fp = True
|
||||
elif sys.version_info >= (3, 4):
|
||||
from pathlib import Path
|
||||
if isinstance(fp, Path):
|
||||
filename = str(fp.resolve())
|
||||
open_fp = True
|
||||
elif hasattr(fp, "name") and isPath(fp.name):
|
||||
# only set the name for metadata purposes
|
||||
filename = fp.name
|
||||
|
||||
# may mutate self!
|
||||
@ -1655,17 +1659,14 @@ class Image(object):
|
||||
else:
|
||||
save_handler = SAVE[format.upper()]
|
||||
|
||||
if filename:
|
||||
if open_fp:
|
||||
fp = builtins.open(filename, "wb")
|
||||
close = 1
|
||||
else:
|
||||
close = 0
|
||||
|
||||
try:
|
||||
save_handler(self, fp, filename)
|
||||
finally:
|
||||
# do what we can to clean up
|
||||
if close:
|
||||
if open_fp:
|
||||
fp.close()
|
||||
|
||||
def seek(self, frame):
|
||||
|
||||
@ -180,8 +180,6 @@ OPEN_INFO = {
|
||||
(MM, 2, (1,), 1, (8, 8, 8, 8), (2,)): ("RGBA", "RGBA"),
|
||||
(II, 2, (1,), 1, (8, 8, 8, 8), (999,)): ("RGBA", "RGBA"), # Corel Draw 10
|
||||
(MM, 2, (1,), 1, (8, 8, 8, 8), (999,)): ("RGBA", "RGBA"), # Corel Draw 10
|
||||
(II, 2, (1, 1, 1, 1), 1, (8, 8, 8, 8), (1,)): ("RGBA", "RGBA"), # OSX Grab
|
||||
(MM, 2, (1, 1, 1, 1), 1, (8, 8, 8, 8), (1,)): ("RGBA", "RGBA"), # OSX Grab
|
||||
(II, 3, (1,), 1, (1,), ()): ("P", "P;1"),
|
||||
(MM, 3, (1,), 1, (1,), ()): ("P", "P;1"),
|
||||
(II, 3, (1,), 2, (1,), ()): ("P", "P;1R"),
|
||||
@ -967,6 +965,13 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||
print("- size:", self.size)
|
||||
|
||||
format = self.tag_v2.get(SAMPLEFORMAT, (1,))
|
||||
if len(format) > 1 and max(format) == min(format) == 1:
|
||||
# SAMPLEFORMAT is properly per band, so an RGB image will
|
||||
# be (1,1,1). But, we don't support per band pixel types,
|
||||
# and anything more than one band is a uint8. So, just
|
||||
# take the first element. Revisit this if adding support
|
||||
# for more exotic images.
|
||||
format = (1,)
|
||||
|
||||
# mode: check photometric interpretation and bits per pixel
|
||||
key = (
|
||||
|
||||
@ -133,6 +133,7 @@ TAGS_V2 = {
|
||||
|
||||
# FIXME add more tags here
|
||||
34665: ("ExifIFD", 3, 1),
|
||||
34675: ('ICCProfile', 7, 1),
|
||||
|
||||
# MPInfo
|
||||
45056: ("MPFVersion", 7, 1),
|
||||
@ -171,7 +172,6 @@ TAGS = {347: 'JPEGTables',
|
||||
33437: 'FNumber',
|
||||
33723: 'IptcNaaInfo',
|
||||
34377: 'PhotoshopInfo',
|
||||
34675: 'ICCProfile',
|
||||
34850: 'ExposureProgram',
|
||||
34852: 'SpectralSensitivity',
|
||||
34853: 'GPSInfoIFD',
|
||||
|
||||
20
README.rst
20
README.rst
@ -6,6 +6,13 @@ Python Imaging Library (Fork)
|
||||
|
||||
Pillow is the friendly PIL fork by `Alex Clark and Contributors <https://github.com/python-pillow/Pillow/graphs/contributors>`_. PIL is the Python Imaging Library by Fredrik Lundh and Contributors.
|
||||
|
||||
.. image:: https://zenodo.org/badge/17549/python-pillow/Pillow.svg
|
||||
:target: https://zenodo.org/badge/latestdoi/17549/python-pillow/Pillow
|
||||
|
||||
.. image:: https://readthedocs.org/projects/pillow/badge/?version=latest
|
||||
:target: http://pillow.readthedocs.org/?badge=latest
|
||||
:alt: Documentation Status
|
||||
|
||||
.. image:: https://img.shields.io/travis/python-pillow/Pillow/master.svg?label=Linux%20build
|
||||
:target: https://travis-ci.org/python-pillow/Pillow
|
||||
:alt: Travis CI build status (Linux)
|
||||
@ -14,8 +21,8 @@ Pillow is the friendly PIL fork by `Alex Clark and Contributors <https://github.
|
||||
:target: https://travis-ci.org/python-pillow/pillow-wheels
|
||||
:alt: Travis CI build status (OS X)
|
||||
|
||||
.. image:: https://img.shields.io/appveyor/ci/Pythonpillow/pillow/master.svg?label=Windows%20build
|
||||
:target: https://ci.appveyor.com/project/Pythonpillow/pillow
|
||||
.. image:: https://img.shields.io/appveyor/ci/python-pillow/Pillow/master.svg?label=Windows%20build
|
||||
:target: https://ci.appveyor.com/project/python-pillow/Pillow
|
||||
:alt: AppVeyor CI build status (Windows)
|
||||
|
||||
.. image:: https://img.shields.io/pypi/v/pillow.svg
|
||||
@ -34,6 +41,7 @@ Pillow is the friendly PIL fork by `Alex Clark and Contributors <https://github.
|
||||
:target: https://landscape.io/github/python-pillow/Pillow/master
|
||||
:alt: Code health
|
||||
|
||||
|
||||
More Information
|
||||
----------------
|
||||
|
||||
@ -50,3 +58,11 @@ More Information
|
||||
- `Changelog <https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst>`_
|
||||
|
||||
- `Pre-fork <https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst#pre-fork>`_
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<div style="float: right">
|
||||
<a href="https://gratipay.com/pillow/">
|
||||
<img alt="Support via Gratipay" src="https://cdn.rawgit.com/gratipay/gratipay-badge/2.3.0/dist/gratipay.png"/>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
BIN
Tests/images/copyleft.tiff
Normal file
BIN
Tests/images/copyleft.tiff
Normal file
Binary file not shown.
BIN
Tests/images/hopper.iccprofile.tif
Normal file
BIN
Tests/images/hopper.iccprofile.tif
Normal file
Binary file not shown.
@ -70,6 +70,11 @@ class TestFileTiff(PillowTestCase):
|
||||
])
|
||||
im.load()
|
||||
|
||||
def test_sampleformat(self):
|
||||
# https://github.com/python-pillow/Pillow/issues/1466
|
||||
im = Image.open("Tests/images/copyleft.tiff")
|
||||
self.assertEqual(im.mode, 'RGB')
|
||||
|
||||
def test_xyres_tiff(self):
|
||||
from PIL.TiffImagePlugin import X_RESOLUTION, Y_RESOLUTION
|
||||
filename = "Tests/images/pil168.tif"
|
||||
|
||||
@ -148,6 +148,17 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||
except struct.error:
|
||||
self.fail("Should not be struct errors there.")
|
||||
|
||||
def test_iccprofile(self):
|
||||
# https://github.com/python-pillow/Pillow/issues/1462
|
||||
im = Image.open('Tests/images/hopper.iccprofile.tif')
|
||||
out = self.tempfile('temp.tiff')
|
||||
|
||||
im.save(out)
|
||||
reloaded = Image.open(out)
|
||||
self.assert_(type(im.info['icc_profile']) is not type(tuple))
|
||||
self.assertEqual(im.info['icc_profile'], reloaded.info['icc_profile'])
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@ -57,6 +57,17 @@ class TestImage(PillowTestCase):
|
||||
self.assertEqual(im.mode, "RGB")
|
||||
self.assertEqual(im.size, (128, 128))
|
||||
|
||||
def test_tempfile(self):
|
||||
# see #1460, pathlib support breaks tempfile.TemporaryFile on py27
|
||||
# Will error out on save on 3.0.0
|
||||
import tempfile
|
||||
im = hopper()
|
||||
fp = tempfile.TemporaryFile()
|
||||
im.save(fp, 'JPEG')
|
||||
fp.seek(0)
|
||||
reloaded = Image.open(fp)
|
||||
self.assert_image_similar(im, reloaded, 20)
|
||||
|
||||
def test_internals(self):
|
||||
|
||||
im = Image.new("L", (100, 100))
|
||||
|
||||
@ -3,6 +3,13 @@ Pillow
|
||||
|
||||
Pillow is the friendly PIL fork by `Alex Clark and Contributors <https://github.com/python-pillow/Pillow/graphs/contributors>`_. PIL is the Python Imaging Library by Fredrik Lundh and Contributors.
|
||||
|
||||
.. image:: https://zenodo.org/badge/17549/python-pillow/Pillow.svg
|
||||
:target: https://zenodo.org/badge/latestdoi/17549/python-pillow/Pillow
|
||||
|
||||
.. image:: https://readthedocs.org/projects/pillow/badge/?version=latest
|
||||
:target: http://pillow.readthedocs.org/?badge=latest
|
||||
:alt: Documentation Status
|
||||
|
||||
.. image:: https://travis-ci.org/python-pillow/Pillow.svg?branch=master
|
||||
:target: https://travis-ci.org/python-pillow/Pillow
|
||||
:alt: Travis CI build status (Linux)
|
||||
@ -11,6 +18,10 @@ Pillow is the friendly PIL fork by `Alex Clark and Contributors <https://github.
|
||||
:target: https://travis-ci.org/python-pillow/pillow-wheels
|
||||
:alt: Travis CI build status (OS X)
|
||||
|
||||
.. image:: https://img.shields.io/appveyor/ci/python-pillow/Pillow/master.svg?label=Windows%20build
|
||||
:target: https://ci.appveyor.com/project/python-pillow/Pillow
|
||||
:alt: AppVeyor CI build status (Windows)
|
||||
|
||||
.. image:: https://img.shields.io/pypi/v/pillow.svg
|
||||
:target: https://pypi.python.org/pypi/Pillow/
|
||||
:alt: Latest PyPI version
|
||||
@ -37,6 +48,12 @@ Pillow is the friendly PIL fork by `Alex Clark and Contributors <https://github.
|
||||
about.rst
|
||||
releasenotes/index.rst
|
||||
|
||||
.. raw:: html
|
||||
|
||||
<a href="https://gratipay.com/pillow/">
|
||||
<img alt="Support via Gratipay" src="https://cdn.rawgit.com/gratipay/gratipay-badge/2.3.0/dist/gratipay.png"/>
|
||||
</a>
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
|
||||
@ -54,12 +54,12 @@ Many of Pillow's features require external libraries:
|
||||
* Pillow has been tested with libjpeg versions **6b**, **8**, and
|
||||
**9** and libjpeg-turbo version **8**.
|
||||
* Starting with Pillow 3.0.0, libjpeg is required by default, but
|
||||
may be disabled with the `--disable-jpeg` flag.
|
||||
may be disabled with the ``--disable-jpeg`` flag.
|
||||
|
||||
* **zlib** provides access to compressed PNGs
|
||||
|
||||
* Starting with Pillow 3.0.0, zlib is required by default, but may
|
||||
be disabled with the `--disable-zlib` flag.
|
||||
be disabled with the ``--disable-zlib`` flag.
|
||||
|
||||
* **libtiff** provides compressed TIFF functionality
|
||||
|
||||
|
||||
@ -42,4 +42,11 @@ have been removed in this release::
|
||||
ImageWin.fromstring()
|
||||
ImageWin.tostring()
|
||||
|
||||
LibJpeg and Zlib are Required by Default
|
||||
----------------------------------------
|
||||
|
||||
The external dependencies on libjpeg and zlib are now required by default.
|
||||
If the headers or libraries are not found, then installation will abort
|
||||
with an error. This behaviour can be disabled with the ``--disable-libjpeg``
|
||||
and ``--disable-zlib`` flags.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user