Replace transparency in PNG images with solid pixel
移除 PNG 图片中的透明层,并且以纯色像素替代
Command-line tools
How-to
2 3 4.
convert input.png -alpha remove output.png
# e.g.
convert b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba.png -flatten b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba_flatten.png
convert b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba.png -alpha off b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba_alpha-off.png # finally, I take it
convert b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba.png -alpha remove b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba_alpha-remove.png # just remove, not fitted
convert b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba.png -background white -alpha remove -alpha off b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba_bg-white_alpha-remove_alpha-off.png
ls -Alh b5*.png
200K b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba.png
177K b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba_alpha-off.png # ✅
186K b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba_alpha-remove.png
186K b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba_bg-white_alpha-remove_alpha-off.png
207K b5ba0bf7b8607ebc1ef605a82c61b9f2a84d7bba_flatten.png
References
- https://imagemagick.org/www/script/convert.php "ImageMagick - Command-line Tools: Convert".
- https://imagemagick.org/discourse-server/viewtopic.php?t=34252 "remove trasparency from PNG( remove alpha) - ImageMagick".
- https://stackoverflow.com/a/28937338 "image processing - Imagemagick: remove alpha component (replace all intermediate alpha pixel with solid pixel) - Stack Overflow".
- https://stackoverflow.com/a/2322750 "imagemagick - Replace transparency in PNG images with white background - Stack Overflow".