3

I found a plugin called oEmbed Featured Image that does absolutely everything I want except output the largest size.

The plugin's default YouTube output size is 480x360. I need to be able to use the full resolution size for at least YouTube/Vimeo.

I figured I can edit the function starting on line 68 in the plugin.

Here is what I've come up with:

public function oembed_dataparse( $return, $data, $url )
{

    if ($yt = $data->provider_name == 'YouTube') 
    {
        if(preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $data->thumbnail_url, $youtube_id))
        $ytvideo_id = $youtube_id;
        $max = get_headers($data->thumbnail_url);

        if (substr($max[0], 9, 3) !== '404') 
        {
            $data->thumbnail_url = 'http://img.youtube.com/vi/$ytvideo_id/maxresdefault.jpg';
        }
    }

    if ($vm = $data->provider_name == 'Vimeo') 
    {
        if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/", $data->thumbnail_url, $vimeo_id))  
            $vmvideo_id = $vimeo_id[3];
            $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vmvideo_id.php"));
            $data->thumbnail_url = $hash[0]['thumbnail_large'];
    }

    if ( ! empty( $data->thumbnail_url ) && ! $this->_thumb_id ) {
         //if ( in_array( @ $data->type, array( 'video' ) ) ) // Only set for video embeds
            $this->set_thumb_by_url( $data->thumbnail_url, @ $data->title );
    }
}
Community
  • 1
  • 1

2 Answers2

2

In this link there are the explanation how you can change the preset of wp. Featured Images & Post Thumbnails I think you could found interesting, probably you don't need use plug-in. the_post_thumbnail( 'full' ); // Original image resolution (unmodified)

In the link it's write: The default image sizes of WordPress are “Thumbnail”, “Medium”, “Large” and “Full Size” (the original size of the image you uploaded). These image sizes can be configured in the WordPress Administration Media panel under >Settings > Media. You can also define your own image size by passing an array with your image dimensions:

he_post_thumbnail(); // Without parameter ->; Thumbnail
the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max)
the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max)
the_post_thumbnail( 'large' ); // Large resolution (default 640px x 640px max)
the_post_thumbnail( 'full' ); // Original image resolution (unmodified)
the_post_thumbnail( array( 100, 100 ) ); // Other resolutions (height, width)

Set the Featured Image Output Size #Set the Featured Image Output Size To be used in the current Theme’s functions.php file. You can use set_post_thumbnail_size() to set the default Featured Image size by resizing the image proportionally (that is, without distorting it):

set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, resize mode

Set the default Featured Image size by cropping the image (either from the sides, or from the top and bottom):

set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, crop mode

In this link you can see more code: https://developer.wordpress.org/reference/functions/the_post_thumbnail/

When using the_post_thumbnail() or related functions, the ‘post-thumbnail’ image size is used by default, though a different size can be specified instead as needed.

Other link i think you can found interesting is this: Image Size and Quality But it's more generic.

The video work in the some way. of course depends from quality of the video in youtube and you can decide how large you want show up. If you don't use a differente media player, you will use a default youtube player and you can use the API for do what you want.

I hope I was helpful.

Marco Romano
  • 456
  • 6
  • 21
  • I think you can not use the plug-in. and try to use cache the default setting of Wordpress. This code are for that not for the plug-in. – Marco Romano Nov 13 '16 at 18:10
1

What you need to do is actually modify you youtube if statement to make it look at $url, not $data->thumbnail_url. That will cause your preg_match() to match correctly, and it will return the correct $yt_videoid for you to use.

Bob Chip
  • 182
  • 2
  • 6