wordpress最新博客的图片签名

On 2010/10/23, in PHP, by lyndon
看到论坛上有人用图片显示最新的blog,觉得很有意思,于是也做了一个。使用时将图片的src指向该php文件即可。
代码如下:
<?php
define(‘MAGPIE_CACHE_AGE’, 60*60) ;// Cache 1 hour in seconds
require( ‘./wp-load.php’ );
require( ‘./wp-includes/rss.php’);
$rss=fetch_rss(‘http://blog.lyphp.com/feed’);
$title=$rss->channel['title'];
$description=$rss->channel['description'];
$link=$rss->channel['link'];
$last_modified=strtotime($rss->last_modified);
$w=350;
$h=216;
$rsspic=’rss.png’;
//unlink($rsspic);
if($last_modified>filemtime($rsspic) || !is_file($rsspic) )
{
$im=imagecreatetruecolor($w,$h);
$bordercolor=imagecolorallocate($im, 0xD8,0xDF,0xEA);
$textcolor=imagecolorallocate($im, 0×20,0×33,0×60);
$greycolor = imagecolorallocate($im, 128, 128, 128);
$bkcolor = imagecolorallocate($im, 0xED,0xEF,0xF4);
$labelcolor=imagecolorallocate($im, 0x5B,0×74,0xA8);
$whitecolor=imagecolorallocate($im, 0xff,0xff,0xff);
$blackcolor=imagecolorallocate($im, 0×00,0×00,0×00);
imagefill($im, 0, 0, $bordercolor);
imagefilledrectangle($im, 1, 1, $w-2, $h-2, $bkcolor);
imagefilledrectangle($im, 2, 2, $w-3, 32, $labelcolor);
$font=’fonts/msyh.ttf’;//中文字体路径,此处是微软雅黑
imagettftext($im, 16, 0, 13, 26, $blackcolor, $font, $title.’ – ‘.$description);
imagettftext($im, 16, 0, 12, 25, $whitecolor, $font, $title.’ – ‘.$description);
imagettftext($im, 12, 0, 13, 54, $greycolor, $font, ‘最新博文’);
imagettftext($im, 12, 0, 12, 53, $textcolor, $font, ‘最新博文’);
for($i=0;$i<6;$i++)
{
imagettftext($im, 10, 0, 20, 75+25*$i, $greycolor, $font, $rss->items[$i]['title']);
}
imagettftext($im, 9, 0, 210, 210, $textcolor, $font, $link);
imagepng($im,$rsspic);
}
$im=imagecreatefrompng($rsspic);
header(‘Content-type: image/png’);
imagepng($im);
imagedestroy($im);
Tagged with:  

6 Responses to wordpress最新博客的图片签名

  1. 小牛哥 says:

    这个显示非常不错,呵呵

  2. 彭超 says:

    您好,我想使用这个,但是我没有搞定,能说一下具体的使用方法吗,谢谢。

    • lyndon says:

      将代码保存成php文件,如rsspic.php,放在网站根目录
      然后访问http://your domain/rsspic.php即可,或者在论坛写签名的地方填
      [img]http://your domain/rsspic.php[/img](换成论坛相应的代码)即可
      注意上传字体文件到根目录下的fonts目录,代码里用的是微软雅黑。换成你的字体文件名就行了。

  3. leochao says:

    拜读
    话说GD还有没有我们比较熟悉的更高层的应用
    小弟刚学php不久
    多多指教
    在phpchina看到你的
    :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>