我花了一个多小时研究这个并阅读了大量的教程。
imgur有一个api可以生成这样的图像 http://imgur.com/api/upload/?url=http://avatars.stocktwits.net/production/8483/thumb-1350729865.png
我试图将输出的图像卷曲,但无法显示任何内容。
<?php
$full = 'http://www.winningportfolio.com/images/styles/iBusiness/style/iconYoutube.png';
function get_image($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://imgur.com/api/upload/?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
//test it out!
$new_url = get_image($full);
echo $new_url;
?>
答案 0 :(得分:0)
这应该有效:
function get_image($url)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://imgur.com/api/upload/?url=' . urlencode($url));
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$lastUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
return $lastUrl;
}
$full = 'http://www.winningportfolio.com/images/styles/iBusiness/style/iconYoutube.png';
var_dump( get_image($full) );
$url
应该是urlencoded curl_getinfo()