You are here

function _pdfpreview_convert_first_page in PDFPreview 6

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

Convert the first page of a PDF document

This function converts the first page of a PDF document using ImageMagick's convert executable and returns TRUE on success, FALSE else. You can provide optional parameters for the convert executable by simply passing them with in an array to the $args parameter. For details about convert arguments see the <a href="http://www.imagemagick.org/Usage/basics/#cmdline">ImageMagick documentation</a>.

Parameters

$source URI to the PDF file:

$dest URI where the preview file will be saved:

$args Optional arguments for the convert executable:

See also

_imagemagick_convert()

_pdfpreview_create_preview()

1 call to _pdfpreview_convert_first_page()
_pdfpreview_create_preview in ./pdfpreview.module
Creates the PDF preview file and returns its URI

File

./pdfpreview.module, line 237
This module creates a formatter for CCK filefields that shows a snapshot of the first page of pdf files as link to the file.

Code

function _pdfpreview_convert_first_page($source, $dest, $args = array()) {
  $source = _pdfpreview_realpath($source) . '[0]';
  $dest = _pdfpreview_realpath($dest);
  $args['quality'] = '-quality ' . escapeshellarg(variable_get('imagemagick_quality', PDFPREVIEW_DEFAULT_QUALITY));
  $args['previewsize'] = '-resize ' . escapeshellarg(variable_get('pdfpreview_previewsize', PDFPREVIEW_DEFAULT_SIZE));
  $context = array(
    'source' => $source,
    'destination' => $dest,
  );
  drupal_alter('imagemagick_arguments', $args, $context);

  // To make use of ImageMagick 6's parenthetical command grouping we need to make
  // the $source image the first parameter and $dest the last.
  // See http://www.imagemagick.org/Usage/basics/#cmdline
  $command = escapeshellarg($source) . ' ' . implode(' ', $args) . ' ' . escapeshellarg($dest);
  if (_imageapi_imagemagick_convert_exec($command, $output, $error) !== TRUE) {
    return FALSE;
  }
  return file_exists($dest);
}