473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

problem saving tif files with PIL


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")
im.save("C:\\test.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=1im = Image.open(r"c:\image1.tif") tag: 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: RGBim.save("C:\\test.tif")

save: 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&...MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.

Jul 18 '05 #1
0 2148

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Zaan | last post by:
www.entropy.ch release for Mac OS X.] Hello, My issue is the following: to promote consistency on a site I'm building, I decided to go for a php scheme where some recurring elements...
12
by: annoyedtuna | last post by:
I'm having nightmares with CSS at the moment. Can anyone help me out? I'm including my stylesheet using the following code <head> <title>My Title.</title> <link rel="stylesheet"...
1
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
1
by: M Keeton | last post by:
I currently have a picture which is stored in a "System.Drawing.Image" variable and I want to save it as a bitmap file. I have tried 2 different approaches and both give me the following error: ...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
1
by: rajeev ranjan | last post by:
Hi to all, I am facing a problem.i have two server for my application. on one i m hosting my web site and on other my database. Through user interface, user can upload the files. Now i want to save...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.