Page 2 of 2

Re: vertical image (page) alignment

Posted: 2017-04-14T07:33:33-07:00
by BradLee
Now I'm looking to so something similar, but horizontally instead.

I don't want to center the cropped images horizontally, because all the pages are different lengths
So I want to add a 28px border to the top instead
Then I want to pad the remainder of the image at the bottom to make it 1024px high.

I've managed to create the following code so far to crop the top and the bottom of the image...

Code: Select all

magick *.png -set filename:f "%[t]" ^
-set option:dimensions "%wx%h" ^
-background black -fuzz 25% ^
-gravity north -splice 0x1 ^
-trim +repage -gravity north -chop 0x1 ^
-gravity south -splice 0x1 ^
-trim +repage -gravity south -chop 0x1 ^
"c:\users\brad\downloads\cleaned\%[filename:f].png"
But I am coming unstuck trying to add a padded border to the top of the image?

Re: vertical image (page) alignment

Posted: 2017-04-14T07:54:34-07:00
by GeeMack
BradLee wrote: 2017-04-14T07:33:33-07:00But I am coming unstuck trying to add a padded border to the top of the image?
Try adding something like this just before the output of your command...

Code: Select all

... -background white -gravity north -splice 0x28 -extent x1024 ...
That sets the background color to white, sets the gravity to north, splices 28 pixels of the background color onto the top, then keeps all that to the north while making the output a total of 1024 pixels high. For the "-extent" operation you can use that "%[dimensions]" variable you set instead of "x1024" to make the output match the original dimensions.

Re: vertical image alignment (updated question)

Posted: 2017-04-14T10:11:34-07:00
by fmw42
If you want to trim the image, then pad 28 at the top and make the result 1024 tall with the trimmed image in the middle horizontally of your original width, then you can do

Code: Select all

magick 1000006441-I00000251-padded-cleaned_zpszrrxna3x.png ^
-set option:wid "%w" ^
-background black -fuzz 8% ^
-gravity east -splice 1x0 ^
-trim +repage -gravity east -chop 1x0 ^
-gravity west -splice 1x0 ^
-trim +repage -gravity west -chop 1x0 ^
-background white -gravity north -extent "%[wid]x1024+0-28" ^
result.png
This assumes that your trim will make the image smaller vertically than 1024-28=996.

If you want something else, please clarify about the width.

Re: vertical image alignment (updated question)

Posted: 2017-04-14T19:15:41-07:00
by BradLee
GeeMack has the right idea. ;)

I want to trim the top, pad 28px at the top, then pad the remaining image to 1024px height.

Re: vertical image alignment (updated question)

Posted: 2017-04-14T19:22:14-07:00
by fmw42
Try this. It stores the original image width. Then it does a trim only at the top, by padding the bottom with one row of black. Then I chop off the bottom black row. Then I extend the image so that it is centered horizontally but shifted down 28 pixels and filled with white to 1024 height.

Code: Select all

magick 1000006441-I00000251-padded-cleaned_zpszrrxna3x.png ^
-set option:wid "%w" ^
-background black -fuzz 10% ^
-gravity south -splice 0x1 ^
-trim +repage -gravity south -chop 0x1 ^
-background white -gravity north -extent "%[wid]x1024+0-28" ^
result.png

Re: vertical image alignment (updated question)

Posted: 2017-04-14T22:42:24-07:00
by BradLee
Thanks fmw42, that worked.
I added the trimming at the bottom however, just to make sure that there were no extraneous not-quite-white pixels.
Cheers. ;)

Thanks GeeMack too.

Have a good Easter guys, whether you celebrate it or not!