Crop and slice a tall image into multiple images (pages).
Posted: 2013-03-01T16:46:47-07:00
I have pages of sheet music in PNG (724×1024 each) format that I would otherwise just put in a PDF to organize but, as pages progress, the print creeps down about 8 pixels on each page and eventually runs between page breaks causing breaks in the print. Page through these examples to see what I'm talking about: 00, 01, 02. As you can see, the print goes a little further down the page each time. I'm using page 1 as a reference point for where the measure (the horizontal lines that the music sits on) sits on subsequent pages so page 1 remains untouched but I need to vertically join (append) all pages starting with page 2, crop 8 pixels from the top of the tall image I created, cut off 1024 pixels to make a new page 2, then continue the process for the remaining pages.
First step I've decided I needed done was to vertically join the individual pages starting with page 2 so that the broken print would be solid. I used this command:
convert -append notation*.png combined.png
This creates a very tall image and that's fine but now I need to figure out how to first crop 8 pixels from the top of the large vertical image, cut off 1024 pixels to make a page, and repeat those two steps to hopefully come out with new individual images/pages that are aligned and don't bleed print off the bottom.
To remove 8 pixels from the top of the tall image, I used this:
convert combined.png -crop +0+8 +repage trimmed.png
This removed 8 pixels from the top of page the tall image but now I need to figure out how to cut 1024 pixels and deliver that to an output%d.png and repeat that process.
My numbers might be shaky but I can figure that stuff out later; I'm currently trying to work out the logistics of how I'm going to make this work. The documentation talks a lot about modifying horizontal images so I'm thinking that maybe I should flip the tall/appended image to lay horizontally and do the cutting that way and then go back and flip them 90-degrees afterwards. My process may also be screwy but I'm tired so I need to take a break. I'm open to suggestions.
First step I've decided I needed done was to vertically join the individual pages starting with page 2 so that the broken print would be solid. I used this command:
convert -append notation*.png combined.png
This creates a very tall image and that's fine but now I need to figure out how to first crop 8 pixels from the top of the large vertical image, cut off 1024 pixels to make a page, and repeat those two steps to hopefully come out with new individual images/pages that are aligned and don't bleed print off the bottom.
To remove 8 pixels from the top of the tall image, I used this:
convert combined.png -crop +0+8 +repage trimmed.png
This removed 8 pixels from the top of page the tall image but now I need to figure out how to cut 1024 pixels and deliver that to an output%d.png and repeat that process.
My numbers might be shaky but I can figure that stuff out later; I'm currently trying to work out the logistics of how I'm going to make this work. The documentation talks a lot about modifying horizontal images so I'm thinking that maybe I should flip the tall/appended image to lay horizontally and do the cutting that way and then go back and flip them 90-degrees afterwards. My process may also be screwy but I'm tired so I need to take a break. I'm open to suggestions.