将(shoutcast状态)脚本的输出写入图像


Write the output of a (shoutcast status) script to an image

我正试图使用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);
?>

呼叫状态是否保存在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;
}