[Tutor] more on wx and tiff
Albert-Jan Roskam
fomcl at yahoo.com
Sun Aug 29 13:23:47 CEST 2010
Hi,
Got it. Thought it would be nice to share it. What set me on the wrong foot
completely was that writing gif files is not possible due to copyright issues.
Below is a very simple version of a conversion function for Group 4 Tif to png.
import wx, os, time
def g4TifToPng(tif, png = None):
if png is None:
png = os.path.splitext(tif)[0] + ".png"
myImg = wx.Image(tif)
if myImg.GetImageCount(tif) == 2:
SECONDPAGE = 1
myImg = wx.Image(tif, type = wx.BITMAP_TYPE_TIF, index = SECONDPAGE)
# myImg = myImg.GetSubImage((0, 2338, 3304, 2338)) # offset h & w, rect
h & w
myImg.SaveFile(png, wx.BITMAP_TYPE_PNG)
newW, newH = myImg.GetSize()
print "%s:: writing file %s (%s x %s pixels)" % \
(time.strftime("%H:%M:%S"), png, newW, newH)
g4TifToPng(tif = "c:/temp/somefile.tif")
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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
________________________________
From: Albert-Jan Roskam <fomcl at yahoo.com>
To: Wayne Werner <waynejwerner at gmail.com>
Cc: Python Mailing List <tutor at python.org>
Sent: Fri, August 27, 2010 8:00:16 PM
Subject: Re: [Tutor] more on wx and tiff
Hi Wayne,
Yep, I considered using PIL, but that package won't read so-called Group 4 Tiffs
[1]. They're two-page, black-and-white scanned forms. I need part of the second
form (i.e., the backside of a certificate). The page contains some hand-written
info which needs to be presented in a simple data entry program, which I made
using Tkinter.
The forms are confidential so they may not leave the company network. And the IT
droids are somewhat paranoid so it's very time-consuming to get some new
executable 'inside' the company network. Beeeh, formalities... :-(
[1] http://www.digitalpreservation.gov/formats/fdd/fdd000024.shtml
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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
________________________________
From: Wayne Werner <waynejwerner at gmail.com>
To: Albert-Jan Roskam <fomcl at yahoo.com>
Cc: Python Mailing List <tutor at python.org>
Sent: Fri, August 27, 2010 6:44:04 PM
Subject: Re: [Tutor] more on wx and tiff
On Fri, Aug 27, 2010 at 11:25 AM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
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.
>
>
Have you tried using the PIL?
http://www.pythonware.com/products/pil/
import Image
i = Image.open("file.tiff")
i.save(open('file.png', 'w'), filetype='png')
I don't know if that was previously suggested, but it should work on any
platform with PIL installed.
HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100829/6e6d1a9d/attachment.html>
More information about the Tutor
mailing list