2016-12-06 111 views
1

我想批量轉換一組PNG files使用ImageMagick旨在將all opaque pixels更改爲specific hexa colorImagemagick將不透明像素轉換爲特定顏色

我想只是一個形象的

for f in *.png; do convert "$f" -colorspace Gray -auto-level "${file%%.png}_gray.png"; done 

結果的轉換,其中轉換爲白色

所有不透明像素我嘗試沒有配料,每個命令成功完成,但始終WITE像素。

我怎麼能設置不透明像素爲#AAA

謝謝!

回答

1

當你說opaque像素時,我不確定是指像素是否具有100%不透明度或具有非零透明度的像素。

方法1

因此,如果我們開始與這個形象是一個藍色的正方形透明環繞和進一步藍色環繞:

enter image description here

然後我們就可以使非 - 透明像素黃色:

convert image.png -fill yellow -colorize 100% result.png 

enter image description here

您將使用'#AAA'代替黃色。

方法2

思考它的另一種方式是將每個RGB像素設定爲10/16,即A上的十六進制規模:

convert image.png -channel RGB -fx '10/16' result.png 

enter image description here

方法3

或者你可能意味着如果你開始w第i這一點 - 這是透明的頂部爲黑色漸變帶紅色邊框:

enter image description here

那麼你希望所有除了完全透明的像素(靠近頂部)成爲#AAA(這裏顯示黃色代替):

convert start.png -channel A -threshold 1 -channel RGB -fill yellow -colorize 100% result.png 

enter image description here

+0

謝謝您的回答我的目標是一些圖標PNG文件轉換爲一個禁用狀態(這就是爲什麼灰色),所以我認爲你的答案是完美的,因爲我想讓全部transp arecious像素透明和其他#AAA顏色! –

+0

我用'convert image.png -fill'#AAA'-colorize 100%inactive/image_inactive.png'來做我所需要的,謝謝;) –

相關問題