The following code is to grabbing the thumbnail image from youtube.

<?
/**
* Function: youtube thumb grabber
*
* @description :
* @param $ : video code, url type (embed/url),size (small/Large),thumb link
* @return : thumb path
*/
if (! function_exists(‘youtube_thumb_grabber’ ))
{

function youtube_thumb_grabber($video_code, $link_type = “embed”, $size = “small”, $thumb_link = “”)
{
if ($video_code != ”)
{
if ($link_type == “embed”)
{

$splited_data = explode(“=”,$video_code);

$video_unique_code = substr(strrchr($splited_data[4],”/”),1,-strlen(strrchr($splited_data[4],”&”)));

}
else if ($link_type == “url”)
{
$splited_data = explode(“=”,$video_code);
$video_unique_code = substr($splited_data[1],0,-strlen(strrchr($splited_data[1],”&”)));
}
else
{
return;
}

if($size == “small”)
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/2.jpg\” alt=\”No image\” /></a>”;
}
else if ($size == “large”)
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/0.jpg\” alt=\”No image\” /></a>”;
}
else
{
return “<a href=\”$thumb_link\”><img src=\”http://img.youtube.com/vi/$video_unique_code/2.jpg\” alt=\”No image\” /></a>”;

}

}

}
}

$video_title_url=”http://www.youtube.com/watch?v=ed3Vd39USYQ”;
$video_code=”<object width=\”560\” height=\”340\”><param name=\”movie\” value=\”http://www.youtube.com/v/ed3Vd39USYQ&hl=en_US&fs=1&\”></param><param name=\”allowFullScreen\” value=\”true\”></param><param name=”allowscriptaccess” value=”always”></param><embed src=”http://www.youtube.com/v/ed3Vd39USYQ&hl=en_US&fs=1&” type=\”application/x-shockwave-flash\” allowscriptaccess=\”always\” allowfullscreen=\”true\” width=\”560\” height=\”340\”></embed></object>”;

echo youtube_thumb_grabber($video_code,”embed”,”large”,$video_title_url);
?>

Hope that this will be useful.

Categories: PHP Code

6 Comments

Abv · November 18, 2009 at 3:28 pm

Thanks

anbazhagan · January 12, 2010 at 9:53 am

HI

super working fine after some modification

igaten · January 21, 2010 at 8:58 am

nice code… thanks

kuldeep · August 27, 2010 at 6:15 pm

nice trick but not professional

John · July 4, 2011 at 9:32 am

Nice information ; thank you for sharing . . .

saeed · September 29, 2012 at 2:12 pm

Good work 🙂 Still one q ??? where u find $video_code ??? (The object)

Only embed available !!!!!!

Leave a Reply

Avatar placeholder

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