Ejemplo n.º 1
0
 /**
  * Convert a picture to a different format and/or resize it.
  *
  * @param $from: File path to the original file.
  * @param $to: File path where the new file should be saved.
  * @param $mime: MIME type of the original image.
  * @param $maxWidth: Maximum width of the new image. No resizing
  *                   is done if this is empty. Can be used without
  *                   specifying maxHeight.
  * @param $maxHeight: Maximum height of the new image. Must be
  *                    used together with $maxWidth.
  */
 protected static function convert($from, $to, $mime, $maxWidth = '', $maxHeight = '')
 {
     $cmd = binarypool_config::getUtilityPath('convert');
     # Make sure all output images are in RGB. This handles incoming CMYK
     # images which some browsers can't display.
     $cmd .= ' -colorspace RGB';
     switch ($mime) {
         case 'image/pdf':
         case 'application/pdf':
             $cmd .= ' -trim';
             break;
         case 'image/gif':
             break;
         default:
             $cmd .= ' -flatten';
             break;
     }
     if ($maxWidth != '') {
         $scale = intval($maxWidth);
         if ($maxHeight != '') {
             $scale .= 'x' . intval($maxHeight);
             # Don't enlarge if the size is already smaller than resized version
             $scale .= '>';
         }
         $cmd .= ' -resize ' . escapeshellarg($scale) . '';
     }
     if ($mime == 'image/jpeg') {
         # Sharpen image
         $cmd .= ' -unsharp 0.5x1';
     }
     $cmd = $cmd . ' ' . escapeshellarg($from) . ' ' . escapeshellarg($to);
     $log = new api_log();
     $log->debug("Resizing image using command: {$cmd}");
     shell_exec($cmd);
 }
Ejemplo n.º 2
0
function cleanSymlinks()
{
    // Do symlink cleanup
    printf("[%10s] Cleaning up symlinks.\n", 'FINAL');
    $cmd = binarypool_config::getUtilityPath('symlinks');
    system("{$cmd} -cdrs " . binarypool_config::getRoot() . "*/created");
    system("{$cmd} -cdrs " . binarypool_config::getRoot() . "*/expiry");
    system("{$cmd} -cdrsv " . binarypool_config::getRoot() . "*/downloaded |grep '/dev/null' |xargs -0 rm");
}
Ejemplo n.º 3
0
 /**
  * Convert a PDF/EPS to JPG/PNG.
  *
  * @param $from:   File path to the original file.
  * @param $to:     File path where the new file should be saved.
  * @param $format: Format to convert to.
  */
 protected static function convert($from, $to, $format)
 {
     $cmd = binarypool_config::getUtilityPath('pdfconverter');
     $cmd .= ' -f ' . $format;
     $cmd .= ' ' . escapeshellarg($from) . ' ' . escapeshellarg($to);
     $log = new api_log();
     $log->debug("Rendering PDF with command: {$cmd}");
     shell_exec($cmd);
 }
Ejemplo n.º 4
0
 protected static function convert($from, $to)
 {
     $cmd = binarypool_config::getUtilityPath('convert');
     $cmd .= ' -density 288 -resize 220 +antialias';
     # Make sure all output images are in RGB. This handles incoming CMYK
     # images which some browsers can't display.
     $cmd .= ' -colorspace RGB -trim ';
     $cmd .= escapeshellarg($from) . ' ' . escapeshellarg($to);
     $log = new api_log();
     $log->debug("Converting PDF/EPS image using command: {$cmd}");
     shell_exec($cmd);
 }
Ejemplo n.º 5
0
 protected static function lint($source, $xsd = null)
 {
     $cmd = binarypool_config::getUtilityPath('xmllint');
     $cmd .= ' --nowarning --nonet --noout';
     if (!is_null($xsd)) {
         $cmd .= ' --schema ' . escapeshellarg($xsd);
     }
     $cmd = $cmd . ' ' . escapeshellarg($source) . ' >/dev/null 2>/dev/null';
     system($cmd, $retval);
     if ($retval != 0) {
         if (is_null($xsd)) {
             throw new binarypool_exception(117, 400, "XML document is not well-formed.");
         } else {
             throw new binarypool_exception(118, 400, "XML document is not valid.");
         }
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Uses `file' on the command line to get the MIME type.
  */
 protected static function getMimeTypeWithCmdLineFile($file)
 {
     $cmd = binarypool_config::getUtilityPath('file');
     $mime = trim(shell_exec("{$cmd} -ib " . escapeshellarg($file)));
     if ($mime == '' || $mime == 'regular file') {
         return null;
     } else {
         return $mime;
     }
 }
Ejemplo n.º 7
0
 function testGetPathOfConvert()
 {
     $convert = binarypool_config::getUtilityPath('convert');
     $this->assertNotEqual(0, strlen($convert));
 }