Take the 2-minute tour ×

the created text with imagettftext does have a completly other color, as it should have (mostly a color of the insertet png figure). Why doesn't it take the color? It must be something in the function resizePictureAndPlaceOnSign, because if i comment it out, it is perfect.

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

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

            CALC RATIO

        $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);


    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
        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");




share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You are creating a paletted image. When you copy the other image on it you are using all available colors, so imagecolorallocate fails and sets $color to false.

To fix the problem do the compositing on a true color image.

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

If for some reason the output needs to be paletted, you can use imagetruecolortopalette() to convert it.

share|improve this answer
thanks that helped very well! –  Furtano Aug 21 '12 at 14:02
add comment

You can try

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

you still won't get exactly the pure blue, for the reasons mcrumley explained, but it could be "close enough".

share|improve this answer
sorry diddn't work! –  Furtano Aug 21 '12 at 14:03
add comment

Your Answer


