2013-02-20 4 views
0

다음 shoutcast 상태 출력을 GD를 사용하여 이미지에 쓰려고하는데 작동하지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?(shoutcast 상태) 스크립트의 출력을 이미지에 작성하십시오.

$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는 다음 SHOUTcast에 상태가 test.txt에 저장됩니다

<?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); 
?> 
+1

shoutcast 상태를 유지할 수 있다면 이미 답을 알고있는 것처럼 보입니다. – LSerni

+0

위에 질문을 업데이트했습니다 ... –

+0

아, 알겠습니다. 미안하지만, 알아 냈어야했는데 .. 음, @ take의 답을 받아 들일 수 있습니다 ;-) – LSerni

답변

1

? 그런 다음 파일의 내용을 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; 
} 
+0

단 한가지주의 할 점 : '\ n'이 줄 구분 기호가 될지는 확실하지 않습니다. '\ r \ n '일 수도 있습니다. 그래서 당신은 정규 표현식을 사용하여 그것을 분할하거나,'foreach' 안에서'$ line = trim ($ line)'을 제일 먼저 처리 할 수 ​​있습니다. – LSerni

+0

내 프로그래밍 기술이 다소 제한적이므로 전체 스크립트가 어떤 모습인지 보여 줄 수 있습니까? –

+0

어쨌든 나는이 시간에 진심으로 감사한다.하지만 나는 데이터를 텍스트로 표시하는 것이 나을지도 모른다. –