2010-12-18 8 views
1

私はこれについていくつかのことを読んだが、私はそれを自分のコードに入れる方法を理解することはできない。Pixel per Pixelイメージ、透明になった黒色

ここでは、次のとおりです。

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; 

} 

オユはそれがどのように見えるかを確認したい場合は、clicクリックここ:http://narks.xtreemhost.com/

し、任意のアイコンをダブルクリックし、ポップアップが表示されます。 (注:任意のアイコン上のdbl- clinkingは、同じ画像を表示します(私はまだこれを修正しませんでした)

どのように私は黒のピクセルをアルファで実際のピクセルのように見せることができますか?

ありがとうございました!

EDITED (私はスペースを節約したいので、新しいコード、私は最初の行を入れて)

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); 
[...] 

に、それが今どのように見えるかを確認上記のウェブサイトを訪問し、ダブルクリックしますアイコン。

EDIT 2 Iだけで(テスト用)試み:

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

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

、次いで

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

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ページのコメントによると、あなたは、アルファ透明度と、そのページ上のPNG画像に関する他のコメントもありimagealphablendingimagesavealpha

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

を呼び出す必要があります。

+0

のためにそれが役に立つことを願っています。私のコードのために編集されたオリジナルの記事を見てください。ここ(http://narks.xtreemhost.com/)を見て、アイコンをダブルクリックしてください。 –

関連する問題