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
Full sized image
Image by Hanin Abouzeid from Pixabay
Image cropped/trimmed using ImageMagick
Image cropped/trimmed using ImageMagick

References

  1. ImageMagick documentation: https://imagemagick.org/script/command-line-options.php#trim