Page 1 of 1

How to batch trim a white/gray legend from the bottom of image?

Posted: 2015-08-30T16:47:12-07:00
by weavermedia
I have several hundred images of varying sizes and orientations. I need to trim them for a project.

Each has a short (~30px) white border across the bottom which contains the filename in gray text. The height of the border varies by a few pixels between images.

I'd like to trim this bottom border off. I did a quick 'n' dirty -chop just to get going on the project but I'm losing between 1-5 pixels from some images.

Code: Select all

mogrify -gravity South -chop 0x30 *.jpg
Is there a way to detect the white area at the bottom, given that it contains gray text also?

Can I scan down the lines until I find a solid white line then chop from there?

Reference image:

Image

Re: How to batch trim a white/gray legend from the bottom of image?

Posted: 2015-08-30T17:02:57-07:00
by snibgo
Being JPEG, you won't get solid white.

I crop the left-most column, turn all pixels that aren't within 2% of white into black, add a 1-thick black border all the way round, and find what I would get from trimming the (black) border.

Code: Select all

convert trees-at-sunset.jpg -crop 1x+0+0 -fuzz 2% -fill Black +opaque White -bordercolor Black -border 1 -format %@ info:

1x27+1+301
The result would be 1 pixel wide and 27 high.

Re: How to batch trim a white/gray legend from the bottom of image?

Posted: 2015-08-30T17:17:56-07:00
by weavermedia
Thanks snibgo, I'll give that try and see what I get.