2010-12-18 2 views
1

나는 이것에 대해 몇 가지를 읽었지 만, 그것을 내 코드에 넣는 방법을 생각할 수는 없습니다. 여기픽셀 이미지 당 픽셀, 투명하게 검은 색으로 바꿈

그것이 :

function go($image) { 
    // Open the image 
    $getimage=imagecreatefrompng($image); 
    //Get the width/height 
    $w = imagesx($getimage); 
    $h = imagesy($getimage); 
    //init Count variable, when it reach the width, skip a line 
    $count = 0; 
    // For each line 
    for($y=0;$y<$h;$y++) { 
     // For each column 
     for($x=0;$x<$w;$x++) { 
     $rgba  = imagecolorat($getimage, $x, $y); 
     $r = ($rgba >> 16) & 0xFF; 
     $g = ($rgba >> 8) & 0xFF; 
     $b = $rgba & 0xFF; 
     $a  = ($rgba & 0x7F000000) >> 24; 
     echo '<div class="pix" style="background-color: rgba('.$r.', '.$g.', '.$b.', '.$a.');"></div>'; 
     $count++; 
     if($count==$w) {echo '<br>'; $count = 0; } 

     } 
    } 
    echo $pixel_gen; 

} 

오유 그것이 카릭 여기, 어떻게 생겼는지보고 싶다면 : http://narks.xtreemhost.com/

그리고 어떤 아이콘을 더블 클릭, 팝업이 나타납니다. (참고 : dbl- 모든 아이콘에 clinking 동일한 이미지를 표시합니다 (나는 아직 이것을 고정하지 않았다)

내가 어떻게 흑인 픽셀을 알파와 함께 실제 픽셀처럼 보이게 만들 수 있습니까?

도움 주셔서 감사합니다.

(새 코드는, 내가 첫 번째 라인을 넣어 내가 공간을 절약하기 원하기 때문에),

function go($image) { 
    // Open the image 
    $getimage=imagecreatefrompng($image); 
    imagealphablending($getimage, false); 
    imagesavealpha($getimage, true); 

    //Get the width/height 
    $w = imagesx($getimage); 
    $h = imagesy($getimage); 
[...] 

는 지금 모양을 보려면 위의 웹 사이트를 방문하고 두 번 클릭하여 수정 됨 상. 함께

I 단지 (A 시험) 시도 2 ​​ EDIT :

$getimage=imagecreatefrompng('iconDB/lib/chat_fav_48.png'); 

header("Content-type: image/png"); 
imagepng($getimage); 
imagedestroy($getimage); 

처음으로 다음

$getimage=imagecreatefrompng('iconDB/lib/chat_fav_48.png'); 
imagealphablending($getimage, false); 
imagesavealpha($getimage, true); 

header("Content-type: image/png"); 
imagepng($getimage); 
imagedestroy($getimage); 

및 괜찮 및 두 번째 화소가 흑색 만든다. 따라서 각 픽셀의 RGB 색상을 표시 할 때와 표시 할 때입니다. 누구든지 실수를 저지른 걸까요?

답변

2

이 질문을 완료하려면 여기에 올바른 작업 코드가 있습니다.

function go($image) { 
// Open the image 
$getimage=imagecreatefrompng($image); 
imagealphablending($getimage, true); 
imagesavealpha($getimage, true); 

    //Get the width/height 
    $w = imagesx($getimage); 
    $h = imagesy($getimage); 
    //init Count variable, when it reach the width, skip a line 
    $count = 0; 
    // For each line 
    for($y=0;$y<$h;$y++) { 
    // For each column 
     for($x=0;$x<$w;$x++) { 
    // Get the image color for this pixel 
    $rgba  = imagecolorat($getimage, $x, $y); 
    $r = ($rgba >> 16) & 0xFF; 
    $g = ($rgba >> 8) & 0xFF; 
    $b = $rgba & 0xFF; 
    $a = ($rgba & 0x7F000000) >> 24; 
    //Calculating the correct Alpha value for rgba display in css 
    $a = (127-$a)/127; 
    echo '<div class="pix" style="background-color: rgba('.$r.', '.$g.', '.$b.', '.$a.');"></div>'; 
    $count++; 
    if($count==$w) {echo '<br>'; $count = 0; } 

     } 
    } 
    echo $pixel_gen; 

} 

나는 그것이 작동하지 않는 사람

1

imagecreatefrompng 페이지에 대한 의견에 따르면, 당신은 imagealphablendingimagesavealpha

imagealphablending($getimage, false); 
imagesavealpha($getimage, true); 

해당 페이지의 알파 투명도 및 PNG 파일에 대한 다른 의견도 있습니다를 호출해야합니다.

+0

유용 할 바랍니다. 내 코드에 대한 편집 된 원본 게시물을 참조하십시오. 여기 (http://narks.xtreemhost.com/)를보고 아이콘을 더블 클릭하십시오. –

관련 문제