• Is there any way to create thumbnails for videos? The plugin works great, but unfortunately, I have a fair amount of video posts on my site, so those posts don’t look as good.

    Is there some easy hack, or will I just have to upload a photo to each video post?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Only if you upload a photo. Since WordPress 2.9 you can upload and set it up as thumbnail, without including it in post text.

    What I did to get video thumbnails is pasting in thumbnailforexcerpts.php after:

    //last try, for images with src without quotes
    	if(empty($src)){
    		preg_match_all('~src=([^\'"]+) ~', $first_image, $matches);
    		$src=$matches[1][0];
    		$srcorig=$matches[1][0];
    	}

    this code:

    if(empty($src)){ // if no images found, try to find a youtube video
    		preg_match_all('~\[youtube [^\>]*\]~', $content, $matches); // find the youtube quicktag
    		$first_image = $matches[0][0];
    		preg_match_all('~\[youtube ([^\'"]+)\]~', $first_image, $matches); // extract the videoId
    		if(!empty($matches[1][0]))
    		{
    			$src="https://img.youtube.com/vi/" . $matches[1][0] . "/2.jpg"; // get the thumbnail from the middle frame of the video
    			$srcorig=$src;
    		}
    	}
    	if(empty($src)){ // if no images found, try to find a vimeo video
    		preg_match_all('~\[vimeo [^\>]*\]~', $content, $matches); // find the vimeo quicktag
    		$first_image = $matches[0][0];
    		preg_match_all('~\[vimeo ([^\'"]+)\]~', $first_image, $matches); // extract the videoId
    		if(!empty($matches[1][0]))
    		{
    			$hash = unserialize(file_get_contents("https://vimeo.com/api/v2/video/".$matches[1][0].".php")); // retrieve serialized data about video and put it in an array
    			$src=$hash[0]['thumbnail_medium']; // show 200px thumbnail
    			$srcorig=$src;
    		}
    	}
    	if(empty($src)){ // if no images found, try to find a google video
    		preg_match_all('~\[googlevideo [^\>]*\]~', $content, $matches); // find the googlevideo quicktag
    		$first_image = $matches[0][0];
    		preg_match_all('~\[googlevideo ([^\'"]+)\]~', $first_image, $matches); // extract the videoId
    		if(!empty($matches[1][0]))
    		{
    			$hash = file_get_contents("https://video.google.com/videofeed?docid=" . $matches[1][0]); // retrieve xml about video
    			preg_match_all('~media:thumbnail url=[\'"]([^\'"]+)[\'"]~',$hash,$matches); // find thumbnail url in xml
    			$src = $matches[1][0];
    			$srcorig=$src;
    		}
    	}

    This script will get the thumbnails from the video host servers, if there are no images found.

    You should have VideoWarrior or similar plugin to use the [youtube videoId] tags.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Thumbnail For Excerpts] Any way to create thumbnails for videos?’ is closed to new replies.