2015-11-04 120 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"); 
?>