SimplePie 是一个开源的 RSS 解析器。显然,SimplePie 可以从它处理的 RSS 提要中缓存图像。但我不知道如何处理文档。
示例代码如下所示
$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->set_image_handler('handler_image.php', 'image'); // handler_image.php?image=67d5fa9a87bad230fb03ea68b9f71090
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();
但是 handler_image 不是 simple.handler 中包含的文件。然而,随着时间的推移下载了各种 hack 和附加组件后,我最终得到了一个名为 handler_image.php 的文件。这实际上是文件中包含的所有代码 -->
require_once('autoloader.php');
SimplePie_Misc::display_cached_file($_GET['i'], '../cache', 'spi');
它什么都不做。
我尝试用 timthumb.php(我已经安装在我的服务器上)替换 handler_image.php,但这也不起作用。
有什么建议吗?
http://simplepie.org/wiki/reference/simplepie/set_image_handler
最佳答案
你想在你的“handler_image.php”文件中做这样的事情:
$feed = new SimplePie();
$cache = $feed->registry->call('Cache', 'get_handler', array($feed->cache_location, $_GET['image'], 'spi'));
$image = $cache->load();
这将为您提供一个包含图像数据的数组,然后您可以按自己喜欢的方式提供它。
关于php - 如何使用 SimplePie 图像处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13979397/