예제 #1
0
파일: Tile.php 프로젝트: endroid/tile
 /**
  * Creates the image.
  */
 public function create()
 {
     $imagine = new Imagine();
     $this->image = $imagine->open(dirname(__FILE__) . '/../assets/background_' . $this->background . '.png');
     $this->renderText();
     if ($this->size != $this->image->getSize()->getHeight()) {
         $box = new Box($this->size, $this->size);
         $this->image->resize($box);
     }
 }
 /**
  * @param $file
  * @param $size
  */
 private function addOverlay($file, $size)
 {
     list($width) = getimagesize($file);
     $size = $size < 1 ? 1 : $size;
     $originalLevelWidth = $width / $size;
     $overlayImagePath = $this->overlayPath . DIRECTORY_SEPARATOR . $originalLevelWidth . '.png';
     if (file_exists($overlayImagePath)) {
         $destination = imagecreatefrompng($file);
         $src = imagecreatefrompng($overlayImagePath);
         $overlayImage = new Image($src);
         $overlayImage->resize(new Box($width, $width));
         $tmpFilePath = $this->kernelcachedir . DIRECTORY_SEPARATOR . sha1(time() . rand()) . '.png';
         $overlayImage->save($tmpFilePath);
         $src = imagecreatefrompng($tmpFilePath);
         $this->imagecopymerge_alpha($destination, $src, 0, 0, 0, 0, $width, $width, 100);
         imagepng($destination, $file);
         imagedestroy($destination);
         imagedestroy($src);
         unlink($tmpFilePath);
     }
 }