[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/options/oembed/providers/ -> YouTube.php (source)

   1  <?php
   2  if (!extension_loaded('gd')) return;
   3  
   4  class MP_oembed_provider_YouTube extends MP_oembed_provider_
   5  {
   6      public $id = 'YouTube';
   7  
   8  	function data2html( $html, $data, $url )
   9      {
  10  
  11          $yu = explode('/', $data->thumbnail_url);
  12  /* thumbnail */    $yt = array_pop($yu); 
  13  /* quality   */ $yq = substr($yt, 0, 2); if (!in_array($yq, array('hq','mq'))) $yq = 'mq';
  14  /* ref video */ $yr = array_pop($yu);
  15  /* new thumb */ $p = "tmp/{$this->id}_{$yr}.png"; $ynf = MP_ABSPATH . $p; $ynu = MP_PATH . $p;
  16  
  17  // modifying image
  18          $image = imagecreatefromjpeg($data->thumbnail_url);
  19  
  20  // if high quality, we create a new canvas without the black bars
  21          if ($yq == 'hq')
  22          {
  23              $canvas = imagecreatetruecolor(480, 270);
  24              imagecopy($canvas, $image, 0, 0, 0, 45, 480, 360);
  25              $image = $canvas;
  26          }
  27  
  28          $yt_w = imagesx($image);
  29          $yt_h = imagesy($image);
  30  
  31  // add the button
  32          $yb = dirname(__FILE__) . '/' . $this->id . '.png';
  33          $ytb = imagecreatefrompng( $yb );
  34  
  35          imagealphablending($ytb, true);
  36  
  37          $ytb_w = imagesx($ytb);
  38          $ytb_h = imagesy($ytb);
  39  
  40  // center the button
  41          $left = round( $yt_w / 2) - round( $ytb_w / 2);
  42          $top  = round( $yt_h / 2) - round( $ytb_h / 2);
  43  
  44  // convert to png
  45          imagecopy( $image, $ytb , $left, $top, 0, 0, $ytb_w, $ytb_h);
  46          imagepng( $image, $ynf, 9);
  47  
  48          $data->thumbnail_url    = $ynu;
  49          $data->thumbnail_width  = $yt_w;
  50          $data->thumbnail_height = $yt_h;
  51  
  52          return $html;
  53      }
  54  }
  55  new MP_oembed_provider_YouTube();


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1