Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Created June 28, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablo-sg-pacheco/f069d43c5307cd29bec961489f1456fd to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/f069d43c5307cd29bec961489f1456fd to your computer and use it in GitHub Desktop.
Class for get an image from a youtube video URL
<?php
namespace OOPFunctions\Youtube;
if ( !class_exists('\OOPFunctions\Youtube\Youtube') ) {
/**
* Description of Youtube
*
* @author Pablo Pacheco <pablo.pacheco@origgami.com.br>
*/
class Youtube {
public static function getImageFromYoutubeUrl( $url,$size = '0' ) {
$id = self::getYoutubeVideoIdFromUrl($url);
$image = self::getImageFromYoutubeId($id,$size);
return $image;
}
public static function getImageFromYoutubeId( $id, $size = '0' ) {
return "http://img.youtube.com/vi/{$id}/{$size}.jpg";
}
public static function getYoutubeVideoIdFromUrl( $url ) {
$queryString = parse_url($url, PHP_URL_QUERY);
parse_str($queryString, $params);
return $params['v'];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment