コード例 #1
0
 /**
  * Tests that the renditions for a movie get generated and saved.
  */
 function testMovieRenditions()
 {
     $dir = self::$BUCKET . 'tmpdir/';
     mkdir($dir, 0755, true);
     copy(realpath(dirname(__FILE__) . '/../res/swiss-kurier.swf'), $dir . 'swiss.swf');
     $renditions = binarypool_render::render('MOVIE', 'test', $dir . 'swiss.swf', $dir);
     // No renditions
     $this->assertEqual($renditions, array());
 }
コード例 #2
0
ファイル: mime.php プロジェクト: pneff/binarypool
 /**
  * Returns the size of the image.
  */
 public function getImageSize($file, $mime = null, $type = null)
 {
     if (is_null($mime)) {
         $mime = self::getMimeType($file);
     }
     if (is_null($type)) {
         $type = binarypool_render::getType($mime);
     }
     if ($mime == 'application/pdf' or $mime == 'image/eps' or $mime == 'application/postscript') {
         // Try to get size from external pdfconverter utility
         $cmd = binarypool_config::getUtilityPath('pdfconverter');
         if (!is_null($cmd)) {
             $cmd .= ' -s ';
             $cmd .= ' ' . escapeshellarg($file);
             $out = shell_exec($cmd);
             $out = explode("\n", $out);
             if (strpos($out[0], 'width:') === 0 && strpos($out[1], 'height:') === 0) {
                 return array('unit' => 'mm', 'width' => intval(substr($out[0], 6)), 'height' => intval(substr($out[1], 7)));
             }
         }
     }
     if ($type == 'IMAGE' || $type == 'MOVIE') {
         $size = getimagesize($file);
         return array('width' => intval($size[0]), 'height' => intval($size[1]), 'unit' => 'px');
     } else {
         return array('width' => null, 'height' => null, 'unit' => null);
     }
 }
コード例 #3
0
ファイル: asset.php プロジェクト: pneff/binarypool
 /**
  * Returns the XML representation of a single item.
  *
  * @param $file: Absolute file name on the disk for this item.
  * @param $rendition: Rendition name. null if this is the original.
  */
 private function getItem($file, $rendition)
 {
     $fproxy = new binarypool_fileobject($file);
     if (!$fproxy->exists()) {
         throw new binarypool_exception(102, 404, "Referenced file in asset does not exist: {$file}");
     }
     $fileinfo = binarypool_fileinfo::getFileinfo($file);
     $mime = $fileinfo['mime'];
     $size = $fileinfo['size'];
     $hash = $fileinfo['hash'];
     $type = is_null($this->type) ? binarypool_render::getType($mime) : $this->type;
     $info = binarypool_mime::getImageSize($file, $mime, $type);
     $isRendition = is_null($rendition) ? 'false' : 'true';
     $isLandscape = $info['width'] > $info['height'] ? 'true' : 'false';
     $xml = '<item type="' . $type . '" isRendition="' . $isRendition . '">';
     $xml .= '<webobject isVisual="true" isAudioOnly="false" unit="' . htmlspecialchars($info['unit']) . '">';
     $xml .= '<objectWidth>' . $info['width'] . '</objectWidth>';
     $xml .= '<objectHeight>' . $info['height'] . '</objectHeight>';
     $xml .= '</webobject>';
     $xml .= '<imageinfo isLandscape="' . $isLandscape . '" unit="' . htmlspecialchars($info['unit']) . '">';
     $xml .= '<width>' . $info['width'] . '</width>';
     $xml .= '<height>' . $info['height'] . '</height>';
     $xml .= '</imageinfo>';
     if ($isRendition) {
         $xml .= '<rendition>' . htmlspecialchars($rendition) . '</rendition>';
     }
     if ($this->locationAbsolute) {
         $xml .= '<location absolute="true">' . $file . '</location>';
     } else {
         $xml .= '<location>' . htmlspecialchars($this->basepath . basename($file)) . '</location>';
     }
     $xml .= '<importsource />';
     $xml .= '<mimetype>' . htmlspecialchars($mime) . '</mimetype>';
     $xml .= '<size>' . $size . '</size>';
     $xml .= '<hash>' . htmlspecialchars($hash) . '</hash>';
     $xml .= '</item>';
     return $xml;
 }
コード例 #4
0
ファイル: storage.php プロジェクト: pneff/binarypool
 private function generateRenditions($type, $dir, $originalFile, $files, $assetFile, $assetObj)
 {
     $exclude = array_keys($files);
     if ($assetObj !== null) {
         $exclude = array_merge(array_keys($assetObj->getRenditions()));
     }
     $outputDir = $this->storage->getRenditionsDirectory($dir);
     $renditions = binarypool_render::render($type, $this->bucketName, $originalFile, $outputDir, $exclude, $assetFile);
     return $this->storage->saveRenditions($renditions, $dir);
 }
コード例 #5
0
ファイル: render_image.php プロジェクト: pneff/binarypool
 /**
  * Determines the extension for the target file based on the input file..
  */
 protected static function getTargetFile($source, $mime, $target)
 {
     $origExtension = binarypool_render::getFileExtension($source);
     $allowedExtensions = array('gif', 'png', 'jpg');
     $newExtension = $origExtension;
     switch ($mime) {
         case 'image/bmp':
         case 'image/tiff':
         case 'application/octet-stream':
         case 'image/jpeg':
             $newExtension = 'jpg';
             break;
         case 'application/pdf':
         case 'image/pdf':
         case 'image/png':
             $newExtension = 'png';
             break;
         case 'image/gif':
             $newExtension = 'gif';
             break;
     }
     if ($newExtension == '' || !in_array($newExtension, $allowedExtensions)) {
         $newExtension = 'jpg';
     }
     return $target . '.' . $newExtension;
 }