function pdfthumb_create_thumb in PDFThumb 7
Create the PDF Covers. And insert the generated image to the media librarie.
Parameters
object $fid: The file_id from file to convert
Return value
object Drupal file object or NULL.
1 call to pdfthumb_create_thumb()
- pdfthumb_process in ./
pdfthumb.module - Find a PDF field for generate a thumb after saving or updating a node
File
- ./
pdfthumb.module, line 252 - Give a way to create pdf thumbnails.
Code
function pdfthumb_create_thumb($fid) {
$file = file_load($fid);
/*$file_directory_temp = file_directory_temp();
$lastCharacterTempPath = substr(file_directory_temp(), -1);
if ($lastCharacterTempPath == "/") {
$file_directory_temp = substr(file_directory_temp(), 0, -1);
}
*/
if ($file->filemime == "application/pdf") {
$src = drupal_realpath($file->uri) . "[0]";
$dest = file_directory_temp() . "/" . $file->filename . ".png";
if (file_exists($dest)) {
unlink($dest);
}
//$exec = variable_get('pdfthumb_convertpath', NULL) . " " . escapeshellarg($src) . " " . escapeshellarg($dest);
$exec = escapeshellcmd(variable_get('pdfthumb_convertpath', NULL)) . " " . escapeshellarg($src) . " " . escapeshellarg($dest);
if (function_exists("exec")) {
exec($exec, $array, $status);
}
elseif (function_exists("system")) {
system($exec, $status);
}
elseif (function_exists("passthru")) {
passthru($exec, $status);
}
if ($status == 0) {
global $user;
$file_uri = file_unmanaged_move($dest);
$file = new stdClass();
$file->uid = $user->uid;
$file->status = 1;
$file->filename = drupal_basename($dest);
$file->uri = $file_uri;
$file->filemime = file_get_mimetype($dest);
$pdf_thumb = file_save($file);
if (variable_get('pdfthumb_link_files', NULL)) {
$fields = array(
'pdffid' => $pdf_thumb->fid,
'fid' => $fid,
);
drupal_write_record('pdfthumb', $fields);
}
return $pdf_thumb;
}
else {
drupal_set_message(t("Error while creating PDF Thumbnails."), "error");
watchdog("pdfthumb", "Error during the converstion from the file @src to @dest with the command @exec", array(
'@src' => $src,
'@dest' => $dest,
'@exec' => $exec,
), WATCHDOG_WARNING);
return NULL;
}
}
else {
return NULL;
}
}