Page 1 of 1

Create equal margins

Posted: 2010-01-17T10:43:30-07:00
by Gerenuk
I have some scanned text (or could be an image) and I want to place it centered on a fixed size page.

Here is the challenge:

The scan could look like

Code: Select all

OptionalHeading                  PageNumber
     TextTextTextTextTextTextTextText
     TextTextTextTextTextTextTextText
     TextTextTextTextTextTextTextText
     TextTextTextTextTextTextTextText
Now I want to compose this image on a page so that I have equal margins to the right and left *of the text block*
If I didn't have the headline and page number, I suppose I could use
- some threshold to make the margins really white
- some despeckle to remove stray spots
- some autocrop which removes all white borders completely
- some (linux bash) command in combination with imagemagick to determine the width of the picture
- some option to add a calculated width white borders as to make the whole picture the desired width

Now the problem is that the *optional* headline and page number should not count for the border calculation.

So in fact, I need to cut out a horizontal strip from the center where I have text only and do some manipulations and calculations there? Now it gets complicating.

Any ideas?

Btw, on top and bottom I probably want anything non-white as a reference point. So no way to handle "optionals" there.

Re: Create equal margins

Posted: 2010-01-24T02:31:39-07:00
by snibgo
You might make a copy, trimming off the top (say) 25% of the image. Maybe also the bottom 5%, as scans can be dirty there.

Do your calculations based on that copy, then apply those numbers to the original.

The solution is messy, but it's bound to be.