[Tutor] more on wx and tiff

Albert-Jan Roskam fomcl at yahoo.com
Fri Aug 27 18:25:12 CEST 2010


Hi again,

Some more questions about tiff conversion. 

First, thanks for your previous replies. I cannot use IrfanView any time soon, 
nor will my boss switch to Linux. 


So I'm trying to do the conversion from tiff to png using the wx package (gif 
would also be fine, but that won't work due to copyright issues -- I pulled 
about half of my hairs out before I found that out ;-). I have to access the 
second page of the tiff file, then write it to a png file. The code below (see 
also http://codepad.org/CV9xZXgi) works for one file only. Two questions:

1--- the program gives a 'tiff library warning', which is related to multipage 
tiff files (http://libtiff.maptools.org/man/TIFFReadDirectory.3tiff.html), but 
it generates the same warning with a single page tiff. The warning is given in a 
little menu (annoying!). How can I prevent or suppress this warning? This is the 
complete warning log:
17:49:54: tiff module: TIFFReadDirectory
17:49:54: TIFF library warning.
17:49:54: tiff module: TIFFReadDirectory
17:49:54: TIFF library warning.
17:49:54: tiff module: TIFFReadDirectory
17:49:54: TIFF library warning.

2--- the program is not closed properly (despite of the destroy() call). What 
should I do to correct this?

As always, thanks in advance for your replies.

Best wishes,
Albert-Jan


import wx, Image
import os, glob

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        self.tifLoc = tifLoc
        self.debug = True
        wx.Frame.__init__(self, parent, id, title, size = (600, 800))
        SECONDPAGE = 1
        self.image = wx.Image(name = self.tifLoc, type = wx.BITMAP_TYPE_TIF, 
index = SECONDPAGE)
        if self.debug:
            h, w = self.image.GetSize()
            print "Reading file '%s' of %s x %s pixels" % (self.tifLoc, h, w )
        self.bitmap = wx.BitmapFromImage(self.image)
        wx.EVT_PAINT(self, self.OnPaint)
        self.Centre()

    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        dc.DrawBitmap(self.bitmap, 0, 0)        
        self.saveIt()

    def saveIt(self):
        pngLoc = os.path.splitext(self.tifLoc)[0] + ".png"
        self.bitmap.SaveFile(pngLoc, wx.BITMAP_TYPE_PNG)

class MyApp(wx.App):

    def OnInit(self):
        frame = MyFrame(None, -1, 'My file')
        frame.Show(False) # do not show pic
        self.SetTopWindow(frame)
        if frame.debug:
            print "... Conversion done!"
        return True

path = "d:/temp"
for f in glob.glob(os.path.join(path, "*.tif")):
    tifLoc = f
    app = MyApp(0)
    app.MainLoop()
    app.Destroy()

 Cheers!!
Albert-Jan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have the 
Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100827/c75c5db9/attachment.html>


More information about the Tutor mailing list