Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
txt to image
#1
Hi,
Sometimes I am handed old files that I cannot OCR, but I can read them via a backdoor.
Simplified, I end up with a few 100.000 very small txt files, each describing a person, with dates, places etc.

I need to find a way to convert these txt files into an image format (tif or png), one to one .
Of course using python, without having to buy (expensive) commercial software, that seems to be available for this purpose.

What would your recommendation be ?
I am curretly looking, but have not found anything practical yet.
thx,
paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#2
This should work
from pathlib import Path
from pygments.formatters import ImageFormatter
import pygments.lexers

lexer = pygments.lexers.TextLexer()
png = pygments.highlight(Path('input.txt').read_text(), lexer, ImageFormatter(line_numbers=False))
Path('output.png').write_bytes(png)
Reply
#3
(Aug-25-2023, 09:02 AM)Gribouillis Wrote: This should work
Yes , it does work !
The records are actually official wedding records, with 98 fields ! (people, places, parrish, dates, witness, occupation...etc)
But obviously not all fields are known for every wedding. This piece of software produces variable size pngs so economy in
kilobytes! (Important if you have zillions)
So thank you Gribouillis.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020