示例#1
0
 /**
  * Creates Deep Zoom image from source file and saves it to destination
  *
  * @param string $source
  * @param string $destination
  * @throw Deepzoom\Exception check source existe and destination is writable
  */
 public function create($source, $destination)
 {
     $this->_imageAdapter->setStreamWrapper($this->_streamWrapper)->setSource($source);
     $dimensions = $this->_imageAdapter->getDimensions();
     $this->_descriptor->setWidth($dimensions['width'])->setHeight($dimensions['height'])->setTileSize($this->_tileSize)->setTileOverlap($this->_tileOverlap)->setTileFormat($this->_tileFormat);
     $aImage = $this->_streamWrapper->getPathInfo($destination);
     /**
      * @todo secure variables
      */
     $imageName = $aImage['filename'];
     $dirName = $aImage['dirname'];
     $imageFile = $this->_streamWrapper->ensure($dirName . DIRECTORY_SEPARATOR . $imageName . '_files');
     foreach (range(0, $this->_descriptor->getNumLevels() - 1) as $level) {
         $levelDir = $this->_streamWrapper->ensure($imageFile . DIRECTORY_SEPARATOR . $level);
         $levelImage = $this->getImage($level);
         $format = $this->_descriptor->getTileFormat();
         $tiles = $this->_descriptor->getNumTiles($level);
         foreach (range(0, $tiles['columns'] - 1) as $column) {
             foreach (range(0, $tiles['rows'] - 1) as $row) {
                 $bounds = $this->_descriptor->getTileBounds($level, $column, $row);
                 $cropLevelImage = clone $levelImage;
                 $cropLevelImage->crop($bounds['x'], $bounds['y'], $bounds['width'], $bounds['height']);
                 $tilePath = $levelDir . DIRECTORY_SEPARATOR . sprintf('%s_%s.%s', $column, $row, $format);
                 $cropLevelImage->save($tilePath);
                 unset($cropLevelImage);
             }
         }
         unset($levelImage);
     }
     $this->_descriptor->save($destination);
 }
示例#2
0
 /**
  * Save descriptor file
  *
  * @param string $source
  * 
  * @return Deepzoom\Descriptor Fluent interface
  */
 public function save($destination)
 {
     $this->_streamWrapper->putContents($destination, $this->dump());
     return $this;
 }