problem saving tif files with PIL

M

mchl gdbt

Hi,

I have several thousand tiffs generated by application A which are read by
application B. I need to remove a few colours from the tiffs and I decided
to try with the python imaging library.

Running under debug mode permits saving my tiff files (with Image.DEBUG=0,
the save doesn't work! see below) , but it truncates the crazy tags in my
tiff and changes the resolution of the image

I realized the resolution had changed when app B spit out garbage and
checked in GIMP which confirmed that the resolution had been changed. The
number of pixels is the same. it went from 96x96ppi as 11.771 x 9.771 to
72 x 72ppi at 15.694 x 13.028, so # of pixels 1130 x 938

Ideally, I want the output image to be identical to the original in every
way. I suspect that it might be enough to just change the size numbers
though I don't know how. I will be messing around with the pixel colours
eventually but the structure of the image must remain basically identical so
that application B works as before.

Any suggestions?

Thanks for any help,
Michael

This the screen output from my idle run.
1) open image
2) save image (doesn't work)
3) debug = 1
4) open image
5) save image (works) fewer tags it seems
6) reload saved image, fewer tags, different resolution, though this is not
apparent within python

im = Image.open(r"c:\image1.tif")Traceback (most recent call last):
File "<pyshell#9>", line 1, in ?
im.save("C:\\test.tif")
File "C:\Local Program Files\Python23\lib\site-packages\PIL\Image.py",
line 1136, in save
SAVE[string.upper(format)](self, fp, filename)
File "C:\Local Program
Files\Python23\lib\site-packages\PIL\TiffImagePlugin.py", line 677, in _save
offset = ifd.save(fp)
File "C:\Local Program
Files\Python23\lib\site-packages\PIL\TiffImagePlugin.py", line 356, in save
data = string.join(map(o32, value), "")
File "C:\Local Program
Files\Python23\lib\site-packages\PIL\TiffImagePlugin.py", line 55, in ol32
return chr(i&255) + chr(i>>8&255) + chr(i>>16&255) + chr(i>>24&255)
TypeError: unsupported operand type(s) for &: 'str' and 'int'

Image.DEBUG=1tag: NewSubfileType (254) - type: long (4) - value: (2,)
tag: ImageWidth (256) - type: long (4) - value: (1130,)
tag: ImageLength (257) - type: long (4) - value: (938,)
tag: BitsPerSample (258) - type: short (3) - value: (8, 8, 8)
tag: Compression (259) - type: short (3) - value: (1,)
tag: PhotometricInterpretation (262) - type: short (3) - value: (2,)
tag: StripOffsets (273) - type: long (4) - value: (3980, 10760, 17540,
24320, 31100, 37880, 44660, 51440, 58220, 65000, 71780, 78560, 85340, 92120,
98900, 105680, 112460, 119240, 126020, 132800, 139580, 146360, 153140,
159920, 166700, 173480, 180260, 187040, 193820, 200600, 207380, 214160,
220940, 227720, 234500, 241280, 248060, 254840, 261620, 268400, 275180,
281960, 288740, 295520, 302300, 309080, 315860, 322640, 329420, 336200,
342980, 349760, 356540, 363320, 370100, 376880, 383660, 390440, 397220,
404000, 410780, 417560, 424340, 431120, 437900, 444680, 451460, 458240,
465020, 471800, 478580, 485360, 492140, 498920, 505700, 512480, 519260,
526040, 532820, 539600, 546380, 553160, 559940, 566720, 573500, 580280,
587060, 593840, 600620, 607400, 614180, 620960, 627740, 634520, 641300,
648080, 654860, 661640, 668420, 675200, 681980, 688760, 695540, 702320,
709100, 715880, 722660, 729440, 736220, 743000, 749780, 756560, 763340,
770120, 776900, 783680, 790460, 797240, 804020, 810800, 817580, 824360,
831140, 837920, 844700, 851480, 858260, 865040, 871820, 878600, 885380,
892160, 898940, 905720, 912500, 919280, 926060, 932840, 939620, 946400,
953180, 959960, 966740, 973520, 980300, 987080, 993860, 1000640, 1007420,
1014200, 1020980, 1027760, 1034540, 1041320, 1048100, 1054880, 1061660,
1068440, 1075220, 1082000, 1088780, 1095560, 1102340, 1109120, 1115900,
1122680, 1129460, 1136240, 1143020, 1149800, 1156580, 1163360, 1170140,
1176920, 1183700, 1190480, 1197260, 1204040, 1210820, 1217600, 1224380,
1231160, 1237940, 1244720, 1251500, 1258280, 1265060, 1271840, 1278620,
1285400, 1292180, 1298960, 1305740, 1312520, 1319300, 1326080, 1332860,
1339640, 1346420, 1353200, 1359980, 1366760, 1373540, 1380320, 1387100,
1393880, 1400660, 1407440, 1414220, 1421000, 1427780, 1434560, 1441340,
1448120, 1454900, 1461680, 1468460, 1475240, 1482020, 1488800, 1495580,
1502360, 1509140, 1515920, 1522700, 1529480, 1536260, 1543040, 1549820,
1556600, 1563380, 1570160, 1576940, 1583720, 1590500, 1597280, 1604060,
1610840, 1617620, 1624400, 1631180, 1637960, 1644740, 1651520, 1658300,
1665080, 1671860, 1678640, 1685420, 1692200, 1698980, 1705760, 1712540,
1719320, 1726100, 1732880, 1739660, 1746440, 1753220, 1760000, 1766780,
1773560, 1780340, 1787120, 1793900, 1800680, 1807460, 1814240, 1821020,
1827800, 1834580, 1841360, 1848140, 1854920, 1861700, 1868480, 1875260,
1882040, 1888820, 1895600, 1902380, 1909160, 1915940, 1922720, 1929500,
1936280, 1943060, 1949840, 1956620, 1963400, 1970180, 1976960, 1983740,
1990520, 1997300, 2004080, 2010860, 2017640, 2024420, 2031200, 2037980,
2044760, 2051540, 2058320, 2065100, 2071880, 2078660, 2085440, 2092220,
2099000, 2105780, 2112560, 2119340, 2126120, 2132900, 2139680, 2146460,
2153240, 2160020, 2166800, 2173580, 2180360, 2187140, 2193920, 2200700,
2207480, 2214260, 2221040, 2227820, 2234600, 2241380, 2248160, 2254940,
2261720, 2268500, 2275280, 2282060, 2288840, 2295620, 2302400, 2309180,
2315960, 2322740, 2329520, 2336300, 2343080, 2349860, 2356640, 2363420,
2370200, 2376980, 2383760, 2390540, 2397320, 2404100, 2410880, 2417660,
2424440, 2431220, 2438000, 2444780, 2451560, 2458340, 2465120, 2471900,
2478680, 2485460, 2492240, 2499020, 2505800, 2512580, 2519360, 2526140,
2532920, 2539700, 2546480, 2553260, 2560040, 2566820, 2573600, 2580380,
2587160, 2593940, 2600720, 2607500, 2614280, 2621060, 2627840, 2634620,
2641400, 2648180, 2654960, 2661740, 2668520, 2675300, 2682080, 2688860,
2695640, 2702420, 2709200, 2715980, 2722760, 2729540, 2736320, 2743100,
2749880, 2756660, 2763440, 2770220, 2777000, 2783780, 2790560, 2797340,
2804120, 2810900, 2817680, 2824460, 2831240, 2838020, 2844800, 2851580,
2858360, 2865140, 2871920, 2878700, 2885480, 2892260, 2899040, 2905820,
2912600, 2919380, 2926160, 2932940, 2939720, 2946500, 2953280, 2960060,
2966840, 2973620, 2980400, 2987180, 2993960, 3000740, 3007520, 3014300,
3021080, 3027860, 3034640, 3041420, 3048200, 3054980, 3061760, 3068540,
3075320, 3082100, 3088880, 3095660, 3102440, 3109220, 3116000, 3122780,
3129560, 3136340, 3143120, 3149900, 3156680, 3163460, 3170240, 3177020)
tag: Orientation (274) - type: short (3) - value: (1,)
tag: SamplesPerPixel (277) - type: short (3) - value: (3,)
tag: RowsPerStrip (278) - type: long (4) - value: (2,)
tag: StripByteCounts (279) - type: long (4) - value: (6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780,
6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780, 6780)
tag: XResolution (282) - type: rational (5) - value: ((96, 1),)
tag: YResolution (283) - type: rational (5) - value: ((96, 1),)
tag: PlanarConfiguration (284) - type: short (3) - value: (1,)
tag: ResolutionUnit (296) - type: short (3) - value: (2,)
tag: PageNumber (297) - type: short (3) - value: (0, 0)
*** Summary ***
- compression: raw
- photometric_interpretation: 2
- planar_configuration: 1
- size: (1130, 938)
format key: (2, 1, (8, 8, 8), ())
- raw mode: RGB
- pil mode: RGBsave: ImageWidth (256) - value: (1130,)
save: ImageLength (257) - value: (938,)
save: BitsPerSample (258) - value: (8, 8, 8)
save: Compression (259) - value: (1,)
save: PhotometricInterpretation (262) - value: (2,)
save: StripOffsets (273) - value: (0,)
save: SamplesPerPixel (277) - value: (3,)
save: RowsPerStrip (278) - value: (938,)
save: StripByteCounts (279) - value: (3179820,)
imnew= Image.open("C:\\test.tif")
tag: ImageWidth (256) - type: short (3) - value: (1130,)
tag: ImageLength (257) - type: short (3) - value: (938,)
tag: BitsPerSample (258) - type: short (3) - value: (8, 8, 8)
tag: Compression (259) - type: short (3) - value: (1,)
tag: PhotometricInterpretation (262) - type: short (3) - value: (2,)
tag: StripOffsets (273) - type: long (4) - value: (128,)
tag: SamplesPerPixel (277) - type: short (3) - value: (3,)
tag: RowsPerStrip (278) - type: short (3) - value: (938,)
tag: StripByteCounts (279) - type: long (4) - value: (3179820,)
*** Summary ***
- compression: raw
- photometric_interpretation: 2
- planar_configuration: 1
- size: (1130, 938)
format key: (2, 1, (8, 8, 8), ())
- raw mode: RGB
- pil mode: RGB

_________________________________________________________________
Powerful Parental Controls Let your child discover the best the Internet has
to offer.
http://join.msn.com/?pgmarket=en-ca...p://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top