Exemplo n.º 1
0
 /**
  * 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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
 }