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

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
weavermedia
Posts: 4
Joined: 2015-08-30T16:32:08-07:00
Authentication code: 1151

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

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

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

Post 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.
snibgo's IM pages: im.snibgo.com
weavermedia
Posts: 4
Joined: 2015-08-30T16:32:08-07:00
Authentication code: 1151

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

Post by weavermedia »

Thanks snibgo, I'll give that try and see what I get.
Post Reply