function pdf_to_image_convert_exec in PDF to ImageField 7.3
Actually execute the shell command.
FWIW, may not need imagemagick module, just for this one func. If you want debugging and Win32 support, use imagemagick.module. Otherwise, here's a short and dirty version of the same thing.
1 call to pdf_to_image_convert_exec()
- pdf_to_image_generate_page in ./
pdf_to_image.module - Generate a single page for the given pdf file.
File
- ./
pdf_to_image.module, line 745 - Generates thumbnail image(s) from an uploaded PDF.
Code
function pdf_to_image_convert_exec($source, $dest, $args = array(), $extra = array()) {
$command = implode(' ', $extra) . ' ' . pdf_to_image_escapeshellarg($source) . ' ' . pdf_to_image_escapeshellarg($dest);
if (function_exists('imagemagick_convert_exec')) {
if (_imagemagick_convert_exec($command, $output, $errors) !== TRUE) {
$errors_txt = 'imageapi imagemagick <pre>' . (is_array($errors) ? implode("\n", $errors) : $errors) . '</pre>';
watchdog('pdf_to_image', $errors_txt, array(), WATCHDOG_ERROR);
return FALSE;
}
return file_exists($dest);
}
// Else do it myself.
// Paranoia.
if (!pdf_to_image_check_imagemagick()) {
drupal_set_message(t('Imagemagick must be installed and the <a href="!admin_path">path on the server set</a> for PDFs to be processed.', array(
'!admin_path' => url('admin/config/media/image-toolkit'),
)), 'error');
return FALSE;
}
$convert_path = variable_get('imagemagick_convert', '/usr/bin/convert');
$response = pdf_to_image_shell_exec($convert_path . ' ' . $command . ' 2>&1');
if (file_exists($dest)) {
return TRUE;
}
else {
watchdog('pdf_to_image', 'pdf_to_image_shell_exec did not create image %dest as expected. %response', array(
'%dest' => $dest,
'%response' => $response,
), WATCHDOG_ERROR);
}
return FALSE;
}