Can’t figure out why the document profile is being changed on a crop, scale and save with PIL. Have tested with an image that had sRGB as color profile, and after it has untagged RGB.
def scale(self, image):
images = []
image.seek(0)
try:
im = PIL.open(image)
except IOError, e:
logger.error(unicode(e), exc_info=True)
images.append({"file": image, "url": self.url, "size": "original"})
for size in IMAGE_WEB_SIZES:
d = cStringIO.StringIO()
try:
im = crop(image, size["width"], size["height"])
im.save(d, "JPEG")
images.append({"file": d, "url": self.scale_url(size["name"]), "size": size})
except IOError, e:
logger.error(unicode(e), exc_info=True)
pass
return images
I am trying to get PIL to save the scaled version with the same colour profile that the original image has.
EDIT: According to this it should be possible http://comments.gmane.org/gmane.comp.python.image/3215, but still not working for me using PIL 1.1.7
PIL has a function to read the icc_profile and also a way to save with icc_profile. So what I did was to open the file to get the icc_profile:
And the add it to the file again on save:
And the full code:
I have tested with both tagged (with icc profile) and untagged jpeg images.