You are here

function _pdfpreview_create_preview in PDFPreview 7.2

Same name and namespace in other branches
  1. 6 pdfpreview.module \_pdfpreview_create_preview()
  2. 7 pdfpreview.module \_pdfpreview_create_preview()

Creates the PDF preview file and returns its URI.

Parameters

object|array $file: A Drupal file structure (array or object).

Return value

string The URI of the newly created preview image, or NULL if the preview image can not be created.

See also

_pdfpreview_convert_first_page()

pdfpreview_field_formatter_view()

1 call to _pdfpreview_create_preview()
pdfpreview_field_formatter_view in ./pdfpreview.module
Implements hook_field_formatter_view()

File

./pdfpreview.module, line 334
This file contains hooks for the pdfpreview module

Code

function _pdfpreview_create_preview($file) {
  if (!is_array($file)) {
    $file = (array) $file;
  }
  $output_filename = _pdfpreview_output_filename($file);

  // Check if a preview already exists.
  if (file_exists($output_filename)) {

    // Check if the existing preview is older than the file itself.
    if (filemtime($file['uri']) <= filemtime($output_filename)) {

      // The existing preview can be used, nothing to do.
      return $output_filename;
    }
    else {

      // Delete the existing but out-of-date preview.
      file_unmanaged_delete($output_filename);

      // Clears cached versions of a the existing preview file in all image styles.
      image_path_flush($output_filename);
    }
  }
  if (_pdfpreview_convert_first_page($file['uri'], $output_filename)) {
    return $output_filename;
  }
  else {
    return NULL;
  }
}