我正在测试 php GD 函数,如下所示:
$height = 200;
$width = 200;
$im = imagecreatetruecolor( $width, $height );
$blue = imagecolorallocate( $im, 0, 0, 64 );
imagefill( $im, 0, 50, $blue );
Header( 'Content-type: image/png' );
imagepng( $im );
imagedestroy( $im );
我试图让图像一半充满蓝色,但没有得到那个结果。有任何关于问题出在哪里的指示吗?
最佳答案
我认为画一个矩形会有帮助:
$height = 200;
$width = 200;
$im = imagecreatetruecolor( $width, $height );
$blue = imagecolorallocate( $im, 0, 0, 64 );
$white = imagecolorallocate($im, 255, 255, 255);
imagefill( $im, 0, 0, $white);
imagefilledrectangle( $im, 0, 0, 100, 200, $blue );
Header( 'Content-type: image/png' );
imagepng( $im );
imagedestroy( $im );
应生成具有白色背景和沿 Y 方向从 0 到 200、沿 X 方向从 0 到 100 的蓝色矩形的图像。
关于php GD图像函数。图像半填充特定颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29687300/