php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21729 imagettftext don't work with a image copied resized from another
Submitted: 2003-01-18 11:17 UTC Modified: 2003-03-02 10:43 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: paolo at i-dome dot com Assigned:
Status: Closed Package: GD related
PHP Version: 4.3.0 OS: Linux
Private report: No CVE-ID: None
 [2003-01-18 11:17 UTC] paolo at i-dome dot com
This code work fine on PHP 4.2.3 compiled with gd2.0.4, but give a image without text with php 4.3 compiled with internal gd support. I have this problem only in the image resized and not with the original image:

    if($width==$isize[0]) //original size: this work
    {
        $im = ImageCreateFromPNG ("bottoni/".$tipo_bottone);
    }
    else // to resize: don't work
    {
        $im1 = ImageCreateFromPNG("bottoni/".$tipo_bottone);
        $im=ImageCreateTrueColor($width, $isize[1]);
        ImageCopy($im, im1,0,0,0,0,$margin_width,$isize[1]);
        ImageCopyResized($im, $im1, $margin_width, 0, $margin_width, 0, $width, $isize[1], round($isize[0]-($margin_width * 2),0), $isize[1]);
        ImageCopy($im, $im1,$margin_width+$width-1,0,$isize[0]-$margin_width,0,$margin_width,$isize[1]);
        ImageDestroy($im1);
    }
    ImageAlphaBlending($im, true);
    $tc  = ImageColorAllocate ($im, $colors[$color][0], $colors[$color][1], $colors[$color][2]);
    imagettftext($im, $size, 0, $center, $margin_height, $tc, $currpath."/fonts/".$font,$testo);
    ImageAlphaBlending($im, false);
    header("Content-Type: image/png\n\n");
    ImagePNG($im);


Thank for support

Paolo Morandi

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-19 07:27 UTC] paolo at i-dome dot com
Don't show the text also with the latest CVS version.
 [2003-01-20 19:22 UTC] pajoye@php.net
Hello,

Can you provide a small script to reproduce your problem, this function works like a charm here.
This line:
$tc  = ImageColorAllocate ($im, $colors[$color][0],
$colors[$color][1], $colors[$color][2]);
can be your problem. Check the $color array, or set error_reporting(E_ALL); to see if they are initialized correctly (btw, use always this flag to develop).

Second point, ImageAlphaBlending is useless in your case, ImageColorAllocate allocates a color with an opaque alpha channel.

thank's for your interest,

pierre
 [2003-01-22 09:14 UTC] paolo at i-dome dot com
This is the original script modified only for running without external parameters. You can download the image bottone1.png by the url http://www.i-dome.com/microtools/bottoni/bottone01.png and the font BOOMBOX.TTF by url http://www.i-dome.com/microtools/fonts/BOOMBOX.TTF
The program must run with this parameters:
testo=the text
larghezza=the width (default 96 pix)

The program run correctly on version 4.2.3 of PHP with gd2.0.4. Also it runs correctly when I give the parameter "larghezza" (with) at the original image width (96).
Thank you very much

Paolo Morandi

<?
    $currpath=substr($SCRIPT_FILENAME,0,strrpos($SCRIPT_FILENAME,"/"));
$margin_width=8; // pixel of margin
$margin_height=23; //pixel from top to write
$default_size=18; //default character dimension
$colors=array(102,153,51);
error_reporting(E_ALL);
    $center=$margin_width;
    $size=$default_size;
    $isize=getimagesize("bottone01.png");
    if(empty($larghezza) || $larghezza < $isize[0])
        $larghezza=$isize[0];
    if($larghezza > 640)
        $larghezza=640;
    $width=$larghezza - ($margin_width * 2);
    $tsize=imagettfbbox($size, 0, "$currpath/BOOMBOX.TTF",$testo);
    $twidth=$tsize[2]-$tsize[0];
// echo "0=$tsize[0]|1=$tsize[1]|2=$tsize[2]|3=$tsize[3]|4=$tsize[4]|5=$tsize[5]|6=$tsize[6]|7=$tsize[7]|<BR>";
// echo "size=$size|width=$width|twidth=$twidth|center=$center|<BR>";
    if($twidth > $width)
    {
        $size=round(($size*($width/$twidth)),0);
        $tsize=imagettfbbox($size, 0, "$currpath/BOOMBOX.TTF",$testo);
        $twidth=$tsize[2]-$tsize[0];
    }
    $center+=round((($width-$twidth)/2),0);
// echo "size=$size|width=$width|twidth=$twidth|center=$center|<BR>";
// imagettftext(image, size, angole, x, y, colore, font, testo)

        $im = ImageCreateFromPNG("bottone01.png");
    if($larghezza==$isize[0]) //in this case run correct
    {
        $im = ImageCreateFromPNG ("bottone01.png");
    }
    else // in this case don't show the text
    {
        $im1 = ImageCreateFromPNG ("bottone01.png");
        $im=ImageCreateTrueColor($larghezza, $isize[1]);
        ImageCopy($im, $im1,0,0,0,0,$margin_width,$isize[1]);
        ImageCopyResized($im, $im1, $margin_width, 0, $margin_width, 0, $width, $isize[1], round($isize[0]-($margin_width * 2),0), $isize[1]);
        ImageCopy($im, $im1,$margin_width+$width-1,0,$isize[0]-$margin_width,0,$margin_width,$isize[1]);
        ImageDestroy($im1);
    }
//	ImageAlphaBlending($im, true);

    $tc  = ImageColorAllocate ($im, $colors[0], $colors[1], $colors[2]);
    imagettftext($im, $size, 0, $center, $margin_height, $tc, "$currpath/BOOMBOX.TTF",$testo);
//	ImageAlphaBlending($im, false);
    header("Content-Type: image/png\n\n");
    ImagePNG($im);
?>
 [2003-03-02 10:43 UTC] paolo at i-dome dot com
With the latest release run
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 21:01:26 2024 UTC