404リーダー
小飼弾2.0
折角なので、404 Blog Not Found専用RSSリーダを作ってみた。
ソースはこんな感じ。
だいぶインチキしているけど縦書きとか本当はどうやるんだろう?
<?php
putenv(‘GDFONTPATH=’.realpath(‘./font’));
require_once ‘XML/Unserializer.php’;$imgfile=‘./tmp/dankogai1.jpg’;
$xmlfile=‘./tmp/dankogai1.rdf’;
$rdf=‘http://blog.livedoor.jp/dankogai/index.rdf’;
if(file_exists($xmlfile)===FALSE || filemtime($xmlfile) < time() – 60*60*2 ){
@copy($rdf,$xmlfile);
}
$xml=@file_get_contents($xmlfile);
if($xml!==FALSE){
$unserializer=& new XML_Unserializer();
$unserializer->setOption(‘parseAttributes’,true);
$unserializer->unserialize($xml);
$data=$unserializer->getUnserializedData();
}
if(isset($_GET['index'])===FALSE){
echo ‘<html><head><title>404Reader</title></head><body>’;
echo ‘<h1>404Reader</h1>’;
echo ‘FONT BY <a xhref=”http://honya.nyanta.jp/” mce_href=”http://honya.nyanta.jp/” >HONYA-JI</a><br />’;
for($i=0;$i<10;$i++){
echo ‘<a xhref=”‘.$data['item'][$i]['link'].‘”>’;
echo ‘<img xsrc=”404reader.php?index=’.$i.‘” width=”220px” border=”0″ /></a>’;
if($i % 4 == 3 ){ echo ‘<br />’; }
}
echo ‘</body></html>’;
exit();
}
$index=(int)$_GET['index'];
$text=array();
if(isset($data['item'][$index]['title'])){
$title=$data['item'][$index]['title'];
$max=min(mb_strlen($title,‘UTF-8′),24);
for($i=$r=0;$i<$max;$i++){
$text[$r].=mb_substr($title,$i,1,‘UTF-8′).“\n”;
if( $i % 8 == 7 ){ $r++; }
}
}
$im=imagecreatefromjpeg($imgfile);
$black=imagecolorallocate($im,0,0,0);
$tmp=array(0,300,315,325);
$x=$tmp[count($text)];
for($i=0;$i<count($text);$i++){
imagettftext($im,17,0,$x-28*$i,50,$black,‘HONYA-JI’,$text[$i]);
}
header(‘Content-Type: image/jpeg’);
imagejpeg($im);
imagedestroy($im);
exit();
飽きたら消すかも。