I'm creating black and white TIF images from scratch and drawing text on them using Python's Imaging Library. Using Python 2.7, PIL 1.1.7 on Windows 7.
To create each image, I use this code
def newBinaryImage(w,h):
return Image.new("1",(w,h),1)
When I open them in any Windows image viewer, they look fine. After I upload them into a database and then view them with a custom made GUI, they look fine in the GUI viewer. However, when I try to print them from the GUI, they become inverted and print out as white text on a black background. (This does not happen when printing it before loading.)
After contacting the vendor who created the custom software, they told us they think the problem might be with the photometricinterpretation tag and it could be fixed by using Group4 compression. Is there a way to do this in PIL, or is there anything that could/should be changed when creating the image?
Here's an Image.DEBUG on one of my images:
>>>Image.open("1010.tif").show()
tag: ImageWidth (256) - type: short (3) - value: (1200,)
tag: ImageLength (257) - type: short (3) - value: (1600,)
tag: Compression (259) - type: short (3) - value: (1,)
tag: PhotometricInterpretation (262) type: short (3) - value: (1,)
tag: StripOffsets (273) - type: long (4) - value: (98,)
tag: RowsPerStrip (278) - type: short (3) - value: (1600,)
tag: StripByteCounts (279) - type: long (4) - value: (240000,)
*** Summary ***
- compression: raw
- photometric_interpretation: 1
- planar_configuration: 1
- fill_order: 1
- size: (1200,1600)
format key: ('II', 1, 1, 1, (1,), ())
- raw mode: 1
- pil mode: 1
I ended up fixing this problem by using ImageMagick. All I did was "convert" each file from type "tif" to type "tif", and it solved the problem! Seems to be a compression issue with PIL.