【发布时间】:2015-05-13 14:31:13
【问题描述】:
我使用此函数从 youtube 图像 url 获取二进制数据。但是在将 api v2 更改为 api v3 之后,我过去使用的功能不再起作用。该函数没有返回任何值。请帮我解决这个问题。
<?php
$thumbnail_link = 'https://i.ytimg.com/vi_webp/s4bw0HQotfU/0.jpg';
if ( function_exists('curl_init') )
{
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $thumbnail_link);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// Getting binary data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$image = curl_exec($ch);
curl_close($ch);
echo $image; //this will return an empty data why is it?
// create & save image;
$img_res = @imagecreatefromstring($image);
if($img_res === false)
return FALSE;
$img_width = imagesx($img_res);
$img_height = imagesy($img_res);
$resource = @imagecreatetruecolor($img_width, $img_height);
if( function_exists('imageantialias'))
{
@imageantialias($resource, true);
}
@imagecopyresampled($resource, $img_res, 0, 0, 0, 0, $img_width, $img_height, $img_width, $img_height);
@imagedestroy($img_res);
switch($ext)
{
case ".gif":
//GIF
@imagegif($resource, $upload_path . $thumb_name);
break;
case ".jpg":
//JPG
@imagejpeg($resource, $upload_path . $thumb_name);
break;
case ".png":
//PNG
@imagepng($resource, $upload_path . $thumb_name);
break;
}
}
?>
【问题讨论】:
标签: api youtube youtube-api