function _pdfpreview_convert_first_page in PDFPreview 7
Same name and namespace in other branches
- 6 pdfpreview.module \_pdfpreview_convert_first_page()
- 7.2 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
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 177 - This file contains hooks for the pdfpreview module
Code
function _pdfpreview_convert_first_page($source, $dest, $args = array()) {
$source = drupal_realpath($source) . '[0]';
$dest = drupal_realpath($dest);
$args['quality'] = '-quality ' . escapeshellarg(variable_get('imagemagick_quality', 75));
$args['previewsize'] = '-resize ' . escapeshellarg(variable_get('pdfpreview_previewsize', '100x100'));
$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 (_imagemagick_convert_exec($command, $output, $error) !== TRUE) {
return FALSE;
}
return file_exists($dest);
}