`fwrite`before`imagepng`在PHP中生成png
我开始写PHP中的图片生成。但我遇到了一件奇怪的事情,如果在imagepng之前执行fwrite,那么输出将是一个无法渲染的损坏图像。代码是:`fwrite`before`imagepng`在PHP中生成png,php,Php,我开始写PHP中的图片生成。但我遇到了一件奇怪的事情,如果在imagepng之前执行fwrite,那么输出将是一个无法渲染的损坏图像。代码是: <?php update(); $my_img = imagecreate( 2000, 200 ); $background = imagecolorallocate( $my_img, 0, 0, 255 ); $text_colour = imagecolorallocate( $my_img, 255, 255, 0 ); $line_co
<?php
update();
$my_img = imagecreate( 2000, 200 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, time(), $text_colour );
imagesetthickness ( $my_img, 5 );
header( "Content-type: image/png" );
imagepng( $my_img );
function update() {
$log_file = fopen("./signature_log.log", "a") or die("issue!");
fwrite($log_file, print_r(getallheaders(), true) . ','. date('l jS \of F Y h:i:s A', time()));
fclose($log_file);
}
您是否可以检查它是否是正确的PNG图像(例如,使用curl将其保存到文件中,并检查它是否具有正确的标头)?我怀疑您的update()
函数在脚本输出中写入了一些内容,弄乱了PNG头。@lmz正是这样。函数在标题之前输出一些内容。