You are here

function theme_imagefield_crop_dynamic_preview in Imagefield Crop 6

1 theme call to theme_imagefield_crop_dynamic_preview()
imagefield_crop_widget_process in ./imagefield_crop_widget.inc

File

./imagefield_crop_widget.inc, line 286

Code

function theme_imagefield_crop_dynamic_preview($file, $resolution, $preview_width = 0) {
  $file = (array) $file;
  if (!is_file($file['filepath'])) {
    return array(
      '<!-- file not found: ' . $file['filepath'] . ' -->',
      '',
    );
  }
  list($width, $height) = explode('x', $resolution);
  if ($preview_width) {
    $height = round($height / ($width / $preview_width));
    $width = $preview_width;
  }
  $image_attributes = array();
  if (list($orig_width, $orig_height, $type, $image_attributes) = @getimagesize($file['filepath'])) {
    $alt = isset($file['alt']) ? $file['alt'] : 'jcrop preview';
    $title = isset($file['title']) ? $file['title'] : '';
    $url = file_create_url($file['filepath']);
    $settings = array(
      'orig_width' => $orig_width,
      'orig_height' => $orig_height,
      'width' => (int) $width,
      'height' => (int) $height,
    );
    $output = '<div class="jcrop-preview-wrapper" style="width:' . $width . 'px;height:' . $height . 'px;overflow:hidden;"><img src="' . check_url($url) . '" alt="' . check_plain($alt) . '" title="' . check_plain($title) . '" class="jcrop-preview" /></div>';
    return array(
      $output,
      $settings,
    );
  }
  return array(
    '<!-- could not get imagesize, possibly corrupt or non image. ' . $file['filepath'] . ' -->',
    '',
  );
}