mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-11 20:21:16 +00:00
previews can be created from files on the disc (e.g. the dropfolder)
This commit is contained in:
parent
0a4e2861ce
commit
c3982f05bf
|
@ -95,10 +95,10 @@ class SeedDMS_Preview_Previewer {
|
|||
$dir = $this->previewDir.'/'.$document->getDir();
|
||||
switch(get_class($object)) {
|
||||
case "SeedDMS_Core_DocumentContent":
|
||||
$target = $dir.'p'.$object->getVersion().'-'.$width.'.png';
|
||||
$target = $dir.'p'.$object->getVersion().'-'.$width;
|
||||
break;
|
||||
case "SeedDMS_Core_DocumentFile":
|
||||
$target = $dir.'f'.$object->getID().'-'.$width.'.png';
|
||||
$target = $dir.'f'.$object->getID().'-'.$width;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
@ -106,7 +106,75 @@ class SeedDMS_Preview_Previewer {
|
|||
return $target;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Create a preview image for a given file
|
||||
*
|
||||
* @param string $infile name of input file including full path
|
||||
* @param string $dir directory relative to $this->previewDir
|
||||
* @param string $mimetype MimeType of input file
|
||||
* @param integer $width width of generated preview image
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
public function createRawPreview($infile, $dir, $mimetype, $width=0, $target='') { /* {{{ */
|
||||
if($width == 0)
|
||||
$width = $this->width;
|
||||
else
|
||||
$width = intval($width);
|
||||
if(!$this->previewDir)
|
||||
return false;
|
||||
if(!is_dir($this->previewDir.'/'.$dir)) {
|
||||
if (!SeedDMS_Core_File::makeDir($this->previewDir.'/'.$dir)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!file_exists($infile))
|
||||
return false;
|
||||
if(!$target)
|
||||
$target = $this->previewDir.$dir.md5($infile).'-'.$width;
|
||||
if($target != '' && (!file_exists($target.'.png') || filectime($target.'.png') < filectime($infile))) {
|
||||
$cmd = '';
|
||||
switch($mimetype) {
|
||||
case "image/png":
|
||||
case "image/gif":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
case "image/svg+xml":
|
||||
$cmd = 'convert -resize '.$width.'x '.$infile.' '.$target.'.png';
|
||||
break;
|
||||
case "application/pdf":
|
||||
case "application/postscript":
|
||||
$cmd = 'convert -density 100 -resize '.$width.'x '.$infile.'[0] '.$target.'.png';
|
||||
break;
|
||||
case "text/plain":
|
||||
$cmd = 'convert -resize '.$width.'x '.$infile.'[0] '.$target.'.png';
|
||||
break;
|
||||
case "application/x-compressed-tar":
|
||||
$cmd = 'tar tzvf '.$infile.' | convert -density 100 -resize '.$width.'x text:-[0] '.$target.'.png';
|
||||
break;
|
||||
}
|
||||
if($cmd) {
|
||||
//exec($cmd);
|
||||
try {
|
||||
self::execWithTimeout($cmd);
|
||||
} catch(Exception $e) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
} /* }}} */
|
||||
|
||||
public function createPreview($object, $width=0) { /* {{{ */
|
||||
if($width == 0)
|
||||
$width = $this->width;
|
||||
else
|
||||
$width = intval($width);
|
||||
$document = $object->getDocument();
|
||||
$file = $document->_dms->contentDir.$object->getPath();
|
||||
$target = $this->getFileName($object, $width);
|
||||
return $this->createRawPreview($file, $document->getDir(), $object->getMimeType(), $width, $target);
|
||||
|
||||
if($width == 0)
|
||||
$width = $this->width;
|
||||
else
|
||||
|
@ -124,7 +192,7 @@ class SeedDMS_Preview_Previewer {
|
|||
if(!file_exists($file))
|
||||
return false;
|
||||
$target = $this->getFileName($object, $width);
|
||||
if($target !== false && (!file_exists($target) || filectime($target) < $object->getDate())) {
|
||||
if($target !== false && (!file_exists($target.'.png') || filectime($target.'.png') < $object->getDate())) {
|
||||
$cmd = '';
|
||||
switch($object->getMimeType()) {
|
||||
case "image/png":
|
||||
|
@ -132,17 +200,17 @@ class SeedDMS_Preview_Previewer {
|
|||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
case "image/svg+xml":
|
||||
$cmd = 'convert -resize '.$width.'x '.$file.' '.$target;
|
||||
$cmd = 'convert -resize '.$width.'x '.$file.' '.$target.'.png';
|
||||
break;
|
||||
case "application/pdf":
|
||||
case "application/postscript":
|
||||
$cmd = 'convert -density 100 -resize '.$width.'x '.$file.'[0] '.$target;
|
||||
$cmd = 'convert -density 100 -resize '.$width.'x '.$file.'[0] '.$target.'.png';
|
||||
break;
|
||||
case "text/plain":
|
||||
$cmd = 'convert -resize '.$width.'x '.$file.'[0] '.$target;
|
||||
$cmd = 'convert -resize '.$width.'x '.$file.'[0] '.$target.'.png';
|
||||
break;
|
||||
case "application/x-compressed-tar":
|
||||
$cmd = 'tar tzvf '.$file.' | convert -density 100 -resize '.$width.'x text:-[0] '.$target;
|
||||
$cmd = 'tar tzvf '.$file.' | convert -density 100 -resize '.$width.'x text:-[0] '.$target.'.png';
|
||||
break;
|
||||
}
|
||||
if($cmd) {
|
||||
|
@ -158,6 +226,20 @@ class SeedDMS_Preview_Previewer {
|
|||
|
||||
} /* }}} */
|
||||
|
||||
public function hasRawPreview($infile, $dir, $width=0) { /* {{{ */
|
||||
if($width == 0)
|
||||
$width = $this->width;
|
||||
else
|
||||
$width = intval($width);
|
||||
if(!$this->previewDir)
|
||||
return false;
|
||||
$target = $this->previewDir.$dir.md5($infile).'-'.$width;
|
||||
if($target !== false && file_exists($target.'.png') && filectime($target.'.png') >= filectime($infile)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} /* }}} */
|
||||
|
||||
public function hasPreview($object, $width=0) { /* {{{ */
|
||||
if($width == 0)
|
||||
$width = $this->width;
|
||||
|
@ -166,12 +248,26 @@ class SeedDMS_Preview_Previewer {
|
|||
if(!$this->previewDir)
|
||||
return false;
|
||||
$target = $this->getFileName($object, $width);
|
||||
if($target !== false && file_exists($target) && filectime($target) >= $object->getDate()) {
|
||||
if($target !== false && file_exists($target.'.png') && filectime($target.'.png') >= $object->getDate()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} /* }}} */
|
||||
|
||||
public function getRawPreview($infile, $dir, $width=0) { /* {{{ */
|
||||
if($width == 0)
|
||||
$width = $this->width;
|
||||
else
|
||||
$width = intval($width);
|
||||
if(!$this->previewDir)
|
||||
return false;
|
||||
|
||||
$target = $this->previewDir.$dir.md5($infile).'-'.$width;
|
||||
if($target && file_exists($target.'.png')) {
|
||||
readfile($target.'.png');
|
||||
}
|
||||
} /* }}} */
|
||||
|
||||
public function getPreview($object, $width=0) { /* {{{ */
|
||||
if($width == 0)
|
||||
$width = $this->width;
|
||||
|
@ -181,8 +277,8 @@ class SeedDMS_Preview_Previewer {
|
|||
return false;
|
||||
|
||||
$target = $this->getFileName($object, $width);
|
||||
if($target && file_exists($target)) {
|
||||
readfile($target);
|
||||
if($target && file_exists($target.'.png')) {
|
||||
readfile($target.'.png');
|
||||
}
|
||||
} /* }}} */
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user