Search code examples
shellubuntucommand

how to cut transparent part from photo with command or shell script


I am having trouble to cut photos in the command line. I need to cut transparent part of a photo and save with command line or shell script Thanks beforehand. If I could do it I would apply it for 4000 photos and it would be a great help More clear explanation what I want to do I have a png picture like this

enter image description here

I want to have an image like this

enter image description here

I could make the image transparent only and is there any way to cut bottom transparent part from a png file

Beforehand thank you very much


Solution

  • The problem you are having that Mark Setchell's Imagemagick command overlooked (probably because he did not have your image at the time) is the orange scroll bar in the lower right corner. You must change the orange to white and then trim as per Mark's suggestion. Your image has an alpha channel but it is fully opaque and so can be removed, also.

    convert input.png -alpha off -fuzz 10% -fill white -opaque "rgb(241,144,105)" -trim +repage output.png
    


    enter image description here

    Note that using too large a fuzz value will also change the color of the red button in the top right corner to white. So -fuzz 10% seems to be a good compromise.