2

imagettftextで作成されたテキストは、必要に応じて完全に他の色になります (ほとんどの場合、挿入された png 図の色)。色が入らないのはなぜ?関数resizePictureAndPlaceOnSignの何かでなければなりません。コメントアウトすれば完璧だからです。

    public function resizePictureAndPlaceOnSign($filename, $new_width,  $dst_x, $dst_y){

        // create figure in memory
        $figure = imagecreatefrompng($filename);


        /* 
            CALC RATIO
        */
        list($width, $height) = getimagesize($filename);

        $vh = ($height/$width);
        $new_height = $vh*$new_width;
        $rnd_new_height = round($new_height, 0); 
        /*  
        */


        // make the figure smaller
        imagecopyresampled($this->picture, $figure, $dst_x, $dst_y, 0, 0, $new_width, $new_height, $width, $height);

        imagedestroy($figure);

    }
    public function drawPicture()
    { 
       // $zufall = rand(1,999);


        // create picture
        $schild_leere_vorlage = imagecreatefrompng("schild_vorlage.png");
        $this->picture = imagecreate(600,192);


        // copy the image into the other image
        # int ImageCopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
        imagecopy($this->picture, $schild_leere_vorlage, 0, 0, 0, 0, 600, 192);


            $filename = "figures/" . $_GET['figure'] . ".png";

            /*********************/
            $this->resizePictureAndPlaceOnSign($filename, 100, 25, 25);


        // create colors
        $color = 0x00000000FF;
        $color =  imagecolorallocate ($this->picture, 0, 0, 255);

        // create text
        imagettftext($this->picture, $this->fontSize , 0, 125, 100,$color , "cooperm.TTF", $this->name);


        // header("Content-Type: image/jpeg");

        imagepng($this->picture);


        //$this->checkFontSize();

        imagedestroy($this->picture);

    }
}
4

2 に答える 2

1

あなたが試すことができます

$color =  imagecolorclosest ($this->picture, 0, 0, 255);

マクラムリーが説明した理由により、まだ純粋な青を正確に取得することはできませんが、「十分に近い」可能性があります.

于 2012-08-20T21:28:03.927 に答える