【发布时间】:2019-12-05 19:49:12
【问题描述】:
首先,对于任何具有 php 知识的人来说,这应该很容易。我正在尝试计算访问过的用途并将数字显示为图像,图像名称为“0.png”-“9.png”,它根据计数选择它,并且应该将其添加到 canvas.png这是一个 296x76 的图像,用作 png 大小为 56x76 的背景。计数器有效,但图像不显示
这里的错误列表后跟奇怪的文字
libpng warning: iCCP: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG
libpng warning: iCCP: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG
libpng warning: iCCP: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG
libpng warning: iCCP: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG
libpng warning: iCCP: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG
//html
<div>
<p> <center> Number of visitors:</center> </p>
<center><img alt="Visitor counter" src="counter.php" /></center>
</div>
//counter.php
<?php
session_start();
$counter_name = "counter.txt";
// Check if a text file exists.
//If not create one and initialize it to zero.
if (!file_exists($counter_name)) {
$f = fopen($counter_name, "w");
fwrite($f,"0");
fclose($f);
}
// Read the current value of our counter file
$f = fopen($counter_name,"r");
$counterVal = fread($f, filesize($counter_name));
fclose($f);
// Has visitor been counted in this session?
// If not, increase counter value by one
if(!isset($_SESSION['hasVisited'])){
$_SESSION['hasVisited']="yes";
$counterVal++;
$f = fopen($counter_name, "w");
fwrite($f, $counterVal);
fclose($f);
}
$counterVal = str_pad($counterVal, 5, "0", STR_PAD_LEFT);
$chars = preg_split('//', $counterVal);
$im = imagecreatefrompng("canvas.png");
$src1 = imagecreatefrompng ("digits/$chars[1].png");
$src2 = imagecreatefrompng ("digits/$chars[2].png");
$src3 = imagecreatefrompng ("digits/$chars[3].png");
$src4 = imagecreatefrompng ("digits/$chars[4].png");
$src5 = imagecreatefrompng ("digits/$chars[5].png");
imagecopymerge($im, $src1, 0, 0, 0, 0, 56, 76, 100);
imagecopymerge($im, $src2, 60, 0, 0, 0, 56, 76, 100);
imagecopymerge($im, $src3, 120, 0, 0, 0, 56, 76, 100);
imagecopymerge($im, $src4, 180, 0, 0, 0, 56, 76, 100);
imagecopymerge($im, $src5, 240, 0, 0, 0, 56, 76, 100);
// Output and free from memory
header('Content-Type: image/png');
echo imagepng($im);
imagedestroy($im);
?>
它应该给出计数的图像并将其显示在我的 index.html 上,但我看到的只是一个“?”图片应该在哪里
【问题讨论】: