How to render a Youtube thumbnail in a template in Drupal 7

后端 未结 3 1429
Happy的楠姐
Happy的楠姐 2021-02-08 03:41

I am using the following modules:

  • media
  • media_youtube
  • Styles

and would like to render a thumbnail of a Youtube video in a templa

3条回答
  •  独厮守ぢ
    2021-02-08 03:55

    One more example, which makes possible to render video thumbnail (vimeo, youtube, qbrick, etc.) with your custom image style.

    $file - File object that you can easily get from media field.

    $wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
    $image_uri = $wrapper->getLocalThumbnailPath();
    
    $image_rendered = theme('image_style', array(
      'style_name' => 'YOUR_IMAGE_STYLE_HERE',
      'path' => $image_uri
    ));
    

    Please note, that if you want to render also image, than you need to check $file->type if it's video or image, because it will use different wrapper objects with different methods.

提交回复
热议问题