I have a script that processes dozens of image files (using Pillow). Recently, I've noticed that my script fails with TIF (CMYK/16) format. So I've created a test case.
images = [
"cmyk-8.tif",
"cmyk-16.tif",
"rgb-8.tif",
"rgb-16.tif",
]
for img_name in images:
path = img_dir + "\\" + img_name
try:
img = Image.open(path)
except OSError as e:
print(e)
else:
print("success: " + img_name)
This produces the following output:
success: cmyk-8.tif
cannot identify image file '...\\cmyk-16.tif'
success: rgb-8.tif
success: rgb-16.tif
So the problem is definitely with the TIF (CMYK/16) format.
How can I open this specific format, or convert it to a openable(?) format (that is RGB/8, RGB/16, CMYK/8) first, and then open it?
In another QA, GDAL was suggested to solve the problem. I've tried it (install GDAL, associate it with Python, and make it work with the current script), but eventually gave up (too problematic). So I've decided just to focus on gdal_translate.
I've installed "gdal-203-1911-x64-core.msi"
from GISInternals, and tried to do the conversion:
"C:\Program Files\GDAL\gdal_translate.exe" -scale -ot byte -of JPEG "C:\Users\%username%\Documents\GitHub\dump\python\tif-cmyk-16\images\cmyk-16.tif" "cmyk-16.jpg"
but it didn't work. I got incorrect conversion:
I'm not familiar with GDAL, so I must be doing something wrong. How do I get it to do the conversion correct?
Also, this is the cmd output:
ERROR 1: Can't load requested DLL: C:\Program Files\GDAL\gdalplugins\ogr_MSSQLSpatial.dll
126: The specified module could not be found.
ERROR 1: Can't load requested DLL: C:\Program Files\GDAL\gdalplugins\ogr_MSSQLSpatial.dll
126: The specified module could not be found.
Input file size is 200, 200
0...10...20...30...40...50...60...70...80...90...100 - done.
Press any key to continue . . .
It seems something is missing, and I don't know if the inccorect conversion is related to this.
Related scripts and output files can be found here.