我正在使用一个变量来定义 PHP 图像中的颜色。有一些代码。
<?php
header ("Content-type: image/png");
ini_set('display_errors', 0);
$width = 36;
$height = 24;
$handle = imagecreatetruecolor ($width, $height) or die ("Cannot Create image"); //image size
$black = 0x1c1c1c; //Black
$hp = ImageColorAllocate ($handle, $_GET["red1"], $_GET["green1"], $_GET["blue1"]);
$mp = $_GET["c1"];
ImageFilledRectangle($handle, 0, 0, 12, 24, $black);
ImageFilledRectangle($handle, 13, 0, 24, 24, $hp);
ImageFilledRectangle($handle, 25, 0, 36, 24, $mp);
ImagePng ($handle);
imagedestroy ($handle);
?>
这会生成一个带有 GD 库的示例图像,该图像应该能够为中间和右侧矩形设置两种自定义颜色,左侧矩形始终为颜色 0x1c1c1c,即灰黑色。中间的矩形工作正常——毕竟,你只是将三个数字传递给 ImageColorAllocate 命令——但右边的矩形出错,出现“格式不正确的数值”。当 $black 以相同的方式格式化时,为什么会发生这种情况?有没有办法让我使用单个变量来定义颜色,而不是三个?
[2021 年 3 月 31 日星期三 15:15:02.838650] [php7:notice] [pid 10089] [client 45.74.102.92:62479] PHP 注意:在 /var/www/html/test.php 中遇到的格式不正确的数值第 15 行