I recently had some images where I had to crop to its main content and get rid of everything else. While I was doing it on icons with transparent backgrounds, it is easier to show on an image with a coloured background. The command to trim the image is:
magick input.png -trim trimmed.png
References
- ImageMagick documentation: https://imagemagick.org/script/command-line-options.php#trim