/**
  *
  * @param Box $box 
  */
 private function mapSection($x, $y)
 {
     $ss = $this->mPanel->getSectionSize();
     $ts = $this->mPanel->getTileSize();
     $sw = $ss->width / $ts->width;
     $sh = $ss->height / $ts->height;
     $box = new Box(new Point(($x + 1) * $sw, ($y + 1) * $sh), new Point($x * $sw, $y * $sh));
     $section = Image::create($ss->width, $ss->height);
     if ($section === false) {
         throw new \Exception();
     }
     $lands = $this->mWorld->findAllTileContainedInBox($box);
     krsort($lands);
     foreach ($lands as $land) {
         $left = ($land->longitude - $box->left) * $ts->width;
         $bottom = ($land->latitude - $box->bottom) * $ts->height;
         $t = $this->mWorld->getLandType($land->color);
         $image = $this->mPanel->getTileImage($t);
         $bottom += $image->height - $ts->height;
         $section->drawImage($left, $section->height - $bottom, $image);
     }
     $path = $this->mDirectory . '/' . $this->mPanel->getName() . '/' . base_convert($x, 10, 36) . '_' . base_convert($y, 10, 36) . '.png';
     @mkdir(dirname($path), 0777, true);
     $section->save($path);
 }
Example #2
0
 /**
  *
  * @return Image 
  */
 public function setImage($path)
 {
     $image = Image::createFromFile($path);
     if (!$image) {
         throw new \InvalidArgumentException();
     }
     if ($this->mWidth !== $image->width || $this->mHeight !== $image->height) {
         throw new \InvalidArgumentException();
     }
     $this->mImagePath = $path;
     return $this->mImage = $image;
 }
 /**
  *
  * @param LandType $type
  * @return Image 
  */
 public function getTileImage(LandType $type)
 {
     if (!isset($this->mTiles[$type->id])) {
         $path = $this->mTileDirectory . '/' . $type->getImagePath();
         $image = Image::createFromFile($path);
         if ($image->height < $this->getTileHeight()) {
             throw new \Exception('Invalid tile image height. (' . $this->getTileHeight() . ')');
         }
         if ($image->width != $this->getTileWidth()) {
             throw new \Exception('Invalid tile image width. (' . $this->getTileWidth() . ')');
         }
         $this->mTiles[$type->id] = $image;
     }
     return $this->mTiles[$type->id];
 }