Colours all but one transparent
<?php
$cmd = "input.jpg -matte \( +clone -fuzz 20% -transparent rgb\(38,134,71\) \) -compose DstOut -composite ";
exec("convert $cmd output.png");
?> The colour to retain in this case is rgb(38,134,71) there is a fuzz factor to allow close colours as well. Do not forget to save to an image format that accepts transparency e.g. png