Trim one border

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
vav

Trim one border

Post by vav »

How can I trim only one border?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

ImageMagick does not have an option to trim one border. You could certainly use the ImageMagick API to access the pixels and trim one border.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Post by glennrp »

Add a 1-pixel thick black row or column opposite the side you want to trim, then add a 1-pixel thick white row or column next to it. Run "convert" with the -trim option. This will trim the desired side and will also remove the white row/column, but won't remove anything from the sides. Then remove the black row/column.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

To trim one broder, your want to -chop it!

See IM Examples...
http://www.cit.gu.edu.au/~anthony/graph ... crop/#chop

The solution GlenRP provided is of corse valid, but a round-about way of doing the same thing.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Post by glennrp »

It's not the same. "-trim" and my solution remove a variable number of rows or columns that contain all the same color pixels. "-chop" or "-crop" (and "-shave") remove a specified number of rows. ../GlennRP
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

I stand corrected. I'll see about adding an example for this.
Done
http://www.cit.gu.edu.au/~anthony/graph ... im_oneside
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply