Create equal margins

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Gerenuk

Create equal margins

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create equal margins

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply