user4039871
user4039871

Reputation:

ImageMagick white out border stripes

I am trying to white out borders of an image. That is, white out 100 px vertical stripe from left, and similarly from right, top, bottom. The following works for left:

mogrify -crop +100+0 -background white -gravity west -splice 100x aaa.tif

But I cannot figure out how to do the same with other sides. I tried many geometries, east, west, this, that, no success. Also please let me know if there is a better alternative than the above command.

Upvotes: 0

Views: 676

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207465

Start with a rose:

enter image description here

I'll do the borders with yellow and magenta so you can see what I am doing on StackOverflow's white background.

All Sides

Shave 10px off all sides and then put 10px back on all sides:

convert rose: -shave 10x10 -bordercolor magenta -border 10 result.png

enter image description here

Right Side

convert rose: -gravity east -chop 10x -background yellow -splice 10x result.png

enter image description here

Left Side

convert rose: -gravity west -chop 10x -background yellow -splice 10x result.png

enter image description here

Top

convert rose: -gravity north -chop x10 -background yellow -splice x10 result.png

enter image description here

Bottom

convert rose: -gravity south -chop x10 -background yellow -splice x10 result.png

enter image description here

Left and Right

convert rose: -shave 10x -bordercolor magenta -border 10x result.png

enter image description here

Top and Bottom

convert rose: -shave x10 -bordercolor magenta -border x10 result.png

enter image description here

Tags: ImageMagick, border, bordering, inside, gravity, one side, multiple sides, edges, framing, frame, overpaint, white-out

If you want the equivalent of Photoshop's "Border Outside" just omit the -shave or -chop.

Upvotes: 2

emcconville
emcconville

Reputation: 24419

Might be worth exploring -extent option, but I feel it could be quicker just to append padding.

For example...(using blue for visual example)

convert -background blue \
        -size 100x xc:blue \
        \( rose: -crop +50+0 \) \
        -size 100x xc:blue \
        +append \
        output.png

padding on both ends

Upvotes: 0

Related Questions