Search code examples
imagemagick

How to remove alpha channeled margins from an image using ImageMagick


I have an image that all four margins are transparent alpha channels and I want to crop all margins and only keep the non-alpha channel parts. Is there any way to do it with ImageMagick? Take this image as an example but consider its transparent margins!

an image with alpha channel margins


Solution

  • You can do that in Imagemagick using -trim to automatically remove the constant transparent regions.

    convert img.png -trim +repage result.png
    

    enter image description here