Say you have an image like this and you want to cut out the white borders at the top and bottom, run it through Imagemagick like below.
❯ convert input.png -trim output.png