You are here

function youtube_get_dimensions in YouTube Field 7

Same name and namespace in other branches
  1. 8 youtube.module \youtube_get_dimensions()

Determines the height and width when given a player size.

Parameters

string $size: (optional) The machine name of the size from youtube_size_options().

string $width: (optional) The width input for custom dimensions.

string $height: (optional) The height input for custom dimensions.

Return value

array An array keyed by 'width' and 'height' with the values to use when theming the video player.

1 call to youtube_get_dimensions()
theme_youtube_video in ./youtube.theme.inc
Theme function for videos.

File

./youtube.inc, line 78
YouTube field helper functions.

Code

function youtube_get_dimensions($size = NULL, $width = NULL, $height = NULL) {
  $dimensions = array();
  if ($size == 'responsive') {
    $dimensions['width'] = '100%';
    $dimensions['height'] = '100%';
  }
  elseif ($size == 'custom') {
    $dimensions['width'] = strstr($width, '%') ? (int) $width . '%' : (int) $width;
    $dimensions['height'] = strstr($height, '%') ? (int) $height . '%' : (int) $height;
  }
  else {

    // Locate the 'x'.
    $strpos = strpos($size, 'x');

    // Width is the first dimension.
    $dimensions['width'] = substr($size, 0, $strpos);

    // Height is the second dimension.
    $dimensions['height'] = substr($size, $strpos + 1, strlen($size));
  }
  return $dimensions;
}