Just in case this CMYK patch does make it into the PIL svn repo...
there's a small bug: before calling invert, self.im should be checked.
This is necessary because the ImageFile.Parser.feed method tries an
open() to see if the image is complete.
Attached is an updated patch.
Index: PIL/JpegImagePlugin.py
===================================================================
--- PIL/JpegImagePlugin.py (revision 460)
+++ PIL/JpegImagePlugin.py (working copy)
@@ -1,6 +1,6 @@
#
# The Python Imaging Library.
-# $Id: JpegImagePlugin.py 2763 2006-06-22 21:43:28Z fredrik $
+# $Id: JpegImagePlugin.py 2199 2004-12-18 08:49:05Z fredrik $
#
# JPEG (JFIF) file handling
#
@@ -32,7 +32,7 @@
__version__ = "0.5"
import array, string
-import Image, ImageFile
+import Image, ImageFile, ImageChops
def i16(c,o=0):
return ord(c[o+1]) + (ord(c[o])<<8)
@@ -270,8 +270,11 @@
handler(self, i)
if i == 0xFFDA: # start of scan
rawmode = self.mode
- if self.mode == "CMYK":
- rawmode = "CMYK;I"
+ # patch by Kevin Cazabon to comment this out - nobody should be using Photoshop 2.5 any more (and it breaks newer versions)
+ # CMYK images are still inverted, we'll fix that just before returning.
+ #if self.mode == "CMYK" and self.info.has_key("adobe"):
+ # rawmode = "CMYK;I" # Photoshop 2.5 is broken!
+
self.tile = [("jpeg", (0,0) + self.size, 0, (rawmode, ""))]
# self.__offset = self.fp.tell()
break
@@ -282,6 +285,10 @@
else:
raise SyntaxError("no marker found")
+ # patch by Kevin Cazabon to re-invert CMYK JPEG files
+ if self.im and self.mode == "CMYK":
+ self.im = ImageChops.invert(self).im
+
def draft(self, mode, size):
if len(self.tile) != 1:
@@ -378,7 +385,7 @@
"RGB": "RGB",
"RGBA": "RGB",
"RGBX": "RGB",
- "CMYK": "CMYK;I",
+ "CMYK": "CMYK",
"YCbCr": "YCbCr",
}
@@ -406,6 +413,10 @@
dpi[0], dpi[1]
)
+ if im.mode == "CMYK":
+ # invert it so it's handled correctly in Photoshop/etc. - Kevin Cazabon.
+ im = ImageChops.invert(im)
+
ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
def _save_cjpeg(im, fp, filename):
_______________________________________________
Image-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/image-sig