2015-11-04 122 views
0

我有這樣的疊加PNG與顏色(PHP)圖像

enter image description here


的圖像,我需要打開在那樣

enter image description here

另外我需要保持透明邊緣。

+0

創建另一個圖像,並相應地顯示出來。 –

+0

嗯....我需要使用php自動化進程。 – remtsoy

+1

所以試過了嗎? –

回答

1

如果你喜歡使用GD了ImageMagick的,你可以做這樣的:

<?php 
// Load the PNG image 
$im = imageCreateFromPng("image.png"); 

// Ensure true colour 
imagepalettetotruecolor($im); 

// Iterate over all pixels 
for ($x = 0; $x < imagesx($im); $x++) { 
    for ($y = 0; $y < imagesy($im); $y++) { 
     // Get color, and transparency of this pixel 
     $col=imagecolorat($im,$x,$y); 
     // Extract alpha 
     $alpha = ($col & 0x7F000000) >> 24; 
     // Make black with original alpha 
     $repl=imagecolorallocatealpha($im,0,0,0,$alpha); 
     // Replace in image 
     imagesetpixel($im,$x,$y,$repl); 
    } 
} 
imagePNG($im,"result.png"); 
?> 

enter image description here

2

你可以讓所有的顏色去黑頭使用ImageMagick的一個門檻功能是這樣的:

<?php 
// Load the PNG image 
$im = new Imagick("image.png"); 

// Make everything black 
$im->thresholdimage(65536); 
$im->writeImage("result.png"); 
?> 

enter image description here

它可能會更合適做雖然這樣說,萬一您曾經使用每通道量化超過16位:

#!/usr/local/bin/php -f 

<?php 
// Load the PNG image 
$im = new Imagick("image.png"); 

// Work out quantum range - probably 255 or 65535 
$m=$im->getQuantumRange(); 
$m=$m["quantumRangeLong"]; 

// Make everything darker than that black 
$im->thresholdimage($m); 
$im->writeImage("result.png"); 
?>