PHP图像字符串颜色不正确

PHP图像字符串颜色不正确,php,image,php-gd,Php,Image,Php Gd,我已经安装了一个PHP-GD库,并为生日愿望编写了一些代码。 但我有一个问题 <?php $path="birthday-images/birthday.png"; $string = "Rohit P Vakharia (February 4th)"; $font = 'ambient.ttf'; $s='birthday-raw/birthday'. 4 .'.png'; //Image Number for different Images

我已经安装了一个PHP-GD库,并为生日愿望编写了一些代码。 但我有一个问题

<?php    
$path="birthday-images/birthday.png";
    $string = "Rohit P Vakharia (February 4th)";
    $font = 'ambient.ttf';
    $s='birthday-raw/birthday'. 4 .'.png';  //Image Number for different Images
    $im= imagecreatefrompng($s);
    $white = imagecolorallocate($im, 255, 255, 255);
    $black = imagecolorallocate($im, 0, 0, 0);
    $counter=1;
    imagettftext($im,40 , 0, 80, 500, $white, $font, $string);
    imagettftext($im,40 , 0, 80, 625, $white, $font, $string);
    imagepng($im,$path);
    imagedestroy($im);
?>

我为两个不同的图像运行了相同的代码。现在我的问题是在一个图像中,我得到了白色的字符串(在黄色图像中),在另一个图像中,我得到了蓝色的字符串(在蓝色图像中)

我希望两个图像具有相同的白色字符串

请给我一些建议,我应该怎么做

为了便于参考,我在这里附上了几张图片

原始生日图像-1

脚本运行后,使用白色字体运行Img

原始生日图像-2


脚本运行后,使用蓝色字体运行Img

检查
imagecolorallocate
@Seti准确返回的内容我已检查
imagecolorallocate
的值是否返回空值,我给出的值为255,但它不是白色请使用
var\u dump($white)了解值和变量类型。第一个图像是int类型,第二个图像是Boolean类型。可能是Boolean FALSE,对吗?如果是,那么它无法分配。