Search code examples
imagemagicktrimimagemagick-convert

How to -trim this image using ImageMagick?


I understand -trim can be used to remove extra whitespace.

How can Imagemagick be used to convert:

Note: The size of the bottom border to be removed is not known.

enter image description here

to

enter image description here

Note: the default -trim flag does not work.

The output of convert -trim pre-trim.png post-trim.png is:

enter image description here

which is missing the borders on the left and right.


Solution

  • Updated Answer

    You can add some strips of colour down one side to protect the other 3 sides, then trim the side you want to trim and then remove the protective strips.

    magick frame.png -gravity north    \
       -background cyan    -splice x10 \
       -background magenta -splice x10 \
       -rotate 90 -trim +repage        \
       -gravity east -chop 10x -rotate -90 result.png
    

    Here is the intermediate image of how it looks with the protective strips prior to trimming:

    enter image description here

    Kudos to Anthony Thyssen for his excellent ImageMagick Usage pages here.

    Original Answer

    You can chop 68 pixels off the bottom with:

    convert frame.png -gravity south -chop x68 result.png