【问题标题】:PHP created Text does not color it should havePHP创建的文本没有颜色它应该有
【发布时间】:2012-08-16 03:56:34
【问题描述】:

使用 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);

    }
}

【问题讨论】:

    标签: php image colors png


    【解决方案1】:

    你可以试试

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

    由于 mcrumley 解释的原因,您仍然无法完全获得纯蓝色,但它可能“足够接近”。

    【讨论】:

      【解决方案2】:

      您正在创建一个调色板图像。当您在其上复制其他图像时,您正在使用所有可用颜色,因此 imagecolorallocate 失败并将$color 设置为 false。

      要解决此问题,请在真彩色图像上进行合成。

      $this->picture = imagecreatetruecolor(600,192);
      

      如果由于某种原因需要对输出进行调色,您可以使用imagetruecolortopalette() 进行转换。

      【讨论】:

        猜你喜欢
        • 2016-02-06
        • 2017-03-17
        • 1970-01-01
        • 2021-03-23
        • 1970-01-01
        • 2016-11-13
        • 2016-05-12
        • 1970-01-01
        相关资源
        最近更新 更多