You are here

function media_browser_plus_media_preview in Media Browser Plus 7

Same name and namespace in other branches
  1. 7.2 includes/media_browser_plus.pages.inc \media_browser_plus_media_preview()

Provide a preview matching to the available resolution of the screen.

_state

Parameters

$form:

$media:

1 string reference to 'media_browser_plus_media_preview'
media_browser_plus_menu in ./media_browser_plus.module
Implements hook_menu().

File

includes/media_browser_plus.pages.inc, line 64
Common pages for the media browser plus module.

Code

function media_browser_plus_media_preview($form, &$form_state, $media) {
  if ($media->type == 'image') {
    $max_width = (int) $_POST['maxWidth'];
    $max_height = (int) $_POST['maxHeight'];

    // echo drupal_render($form['preview']);
    list($sx, $sy) = getimagesize(drupal_realpath($media->uri));
    if ($sx > $max_width) {
      $ratio = bcdiv($max_width, $sx, 5);
      $sx = $max_width;
      $sy = bcmul($sy, $ratio, 0);
    }
    if ($sy > $max_height) {
      $ratio = bcdiv($max_height, $sy, 5);
      $sy = $max_height;
      $sx = bcmul($sx, $ratio, 0);
    }
    $uri = '';
    if (strstr($media->uri, 'private://')) {
      $stream = new DrupalPrivateStreamWrapper();
    }
    else {
      $stream = new DrupalPublicStreamWrapper();
    }
    $stream
      ->setUri($media->uri);
    $uri = $stream
      ->getExternalUrl($media->uri);
    echo '<div class="preview-metadata" title="' . $media->filename . '">' . '<img width="' . $sx . '" height="' . $sy . '" src="' . $uri . '" /></div>';
  }
  else {
    $form['preview'] = media_get_thumbnail_preview(file_load($media->fid), TRUE);
    echo drupal_render($form['preview']);
  }
  die;
}