1. Mikhail Korobov
  2. psd-tools


Mikhail Korobov  committed 5b24d59

LittleCMS is made optional. Fix GH-17

  • Participants
  • Parent commits 46d874f
  • Branches default

Comments (0)

Files changed (3)

File README.rst

View file
     Unfortunately I don't have a license for Adobe Photoshop and use GIMP for
     testing; PNG screenshots may be necessary in cases where GIMP fails.
-In order to run tests, install `tox <http://tox.testrun.org>`_ and type
+In order to run tests, make sure PIL/Pillow is built with LittleCMS support,
+install `tox <http://tox.testrun.org>`_ and type

File src/psd_tools/decoder/image_resources.py

View file
         from PIL import ImageCms
     except ImportError:
+        warnings.warn("ICC profile is not handled; colors could be incorrect. "
+                      "Please build PIL or Pillow with littlecms/littlecms2 "
+                      "support.")
         return data
     return ImageCms.ImageCmsProfile(io.BytesIO(data))

File src/psd_tools/user_api/pil_support.py

View file
 from psd_tools import icc_profiles
-    from PIL import Image, ImageCms
+    from PIL import Image
     if hasattr(Image, 'frombytes'):
         frombytes = Image.frombytes
-        frombytes = Image.fromstring
+        frombytes = Image.fromstring  # PIL and older Pillow versions
 except ImportError:
     Image = None
+    from PIL import ImageCms
+except ImportError:
+    ImageCms = None
 def extract_layer_image(decoded_data, layer_index):
         raise NotImplementedError()
     if icc_profile is not None:
+        assert ImageCms is not None
             if color_mode in [ColorMode.RGB, ColorMode.CMYK]:
                 merged_image = ImageCms.profileToProfile(merged_image, icc_profile, icc_profiles.sRGB, outputMode='RGB')
             elif color_mode == ColorMode.GRAYSCALE:
                 ImageCms.profileToProfile(merged_image, icc_profile, icc_profiles.gray, inPlace=True, outputMode='L')
         except ImageCms.PyCMSError as e:
             # PIL/Pillow/(old littlecms?) can't convert some ICC profiles