如何转换颜色?

时间:2018-07-20 08:30:09

标签: php base64

此代码结果enter image description here我想将此重采样像素颜色转换为反向,黑色像素将为白色,白色像素为黑色 我的这将是一个问题。怎么把白色像素转换成png格式? This İmage

  $width=10;
        $height=16;
        $resimBase64 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8AAAD/AAAAAAAAAAAAAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAAAAAAAAAAAA/wAAAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAAAAAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8AAAD/AAAA/wAAAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/wAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP8AAAD/AAAA/wAAAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAAAAAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAAAAAAAAAAAAAAAAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAAAAAAAAA==";

        $byteArray=array();
        foreach(str_split(base64_decode($resimBase64)) as $byte)
        {
            $byteArray[] = ord($byte);
        }
        //print_r($byteArray);
        //exit;
        header ('Content-type: image/png');
        $im = @imagecreatetruecolor($width, $height) or die('GD2 resim akımı ilklendirilemedi');
        //$black = imagecolorallocate($im,255,255,255);
        $i=0;

        for( $y=0;$y<$height;$y++){
            for( $x=0;$x<$width;$x++){
                //imagesetpixel($im,$x,$y,$black);
                $b=$byteArray[$i+0];
                $g=$byteArray[$i+1];
                $r=$byteArray[$i+2];
                $a=$byteArray[$i+3];
                $color=imagecolorallocate($im,$a,$a,$a);
                $white = imagecolorallocate($im, 255, 255, 255);
                imagefill($im, 0, 0, $white);
                //echo $a."<br/>\n";
                imagesetpixel($im,$x,$y,$color);
                $i=$i+4;
            }
        }
            imagefilter($im, IMG_FILTER_NEGATE);
imagepng($im);
    imagedestroy($im);




  [1]: https://i.stack.imgur.com/oe1Cn.png

2 个答案:

答案 0 :(得分:2)

使用GD库,您可以使用类型为%UserProfile%的{​​{3}}(否定)。

这应该做到:

IMG_FILTER_NEGATE

答案 1 :(得分:0)

我这将是一个问题。怎么把白色像素转换成png格式?  This İmage