2016-02-17 45 views
0

我有一個用戶以PNG格式上傳的標識。將彩色標識轉換爲白色標識

enter image description here

我的目標是轉換用戶上傳到白顏色的標誌。

像這樣 - 讓它在黑暗背景下看起來不錯。

enter image description here

我可以將其導出並使用Photoshop來得到我想要的,但我想以編程方式做到這一點。

是否有任何API /軟件包可以幫助我實現這一目標?

我願意接受任何建議。隨意。


我已經試過

PHP

<?php 

    $logoSrc = '/images/logo.png?q=<?php echo microtime();'; 
    $logo = imagecreatefromstring($logoSrc); 
    $white = imagecolorallocate($logo, 255, 255, 255); 
    imagecolortransparent($logo, $white); 

    ?> 

IMG

<img class="logo-external" src="{{imagefilter($logo, IMG_FILTER_COLORIZE, 255, 255, 255)}}"> 

結果

imagecreatefromstring(): Data is not in a recognized format

回答

0

在PHP中,你可以用imagecolortransparent刪除空格:

$white = imagecolorallocate($img, 255, 255, 255); 
imagecolortransparent($img, $white); 

然後嘗試使用imagefilter使剩餘的圖像白色:

imagefilter($img, IMG_FILTER_COLORIZE, 255, 255, 255) 
相關問題