我正在尝试使用GD将(shoutcast status)脚本的以下输出写入图像,但它不起作用。我究竟做错了什么?
$string = "/home/test.txt";
使用上面的内容只显示文件的路径而不是它的内容。
输出:
psytrance.value 37
breaks.value 8
dubstep.value 6
reggae.value 130
oldskool.value 5
ambient.value 81
test.value <- this should be ignored!
complete.value 267
PHP:
<?php
header ("Content-type: image/png");
$string = "/home/test.txt";
// try changing this as well
$font = 4;
$width = imagefontwidth($font) * strlen($string) ;
$height = imagefontheight($font) ;
$im = imagecreatefrompng("/home/banner2.png");
$x = imagesx($im) - $width ;
$y = imagesy($im) - $height;
$backgroundColor = imagecolorallocate ($im, 255, 255, 255);
$textColor = imagecolorallocate ($im, 0, 0,0);
imagestring ($im, $font, $x, $y, $string, $textColor);
imagepng($im);
?>
答案 0 :(得分:1)
shoutcast状态保存在test.txt
?然后你必须将文件的内容写入你的PNG。
$content = file_get_contents ($string);
[...]
$lines = explode("\n", $content);
foreach ($lines as $line) {
if (strstr("test.value", $line) !== false) continue;
imagestring ($im, $font, $x, $y, $string, $textColor);
$y += 20;
}