예제 #1
0
파일: Shadow.php 프로젝트: jelito/imager
 /**
  * @param Image $image
  * @return resource
  */
 public function apply(Image $image)
 {
     $originalHeight = $image->getHeight();
     $originalWidth = $image->getWidth();
     $canvasHeight = $originalHeight + 2 * $this->w;
     $canvasWidth = $originalWidth + 2 * $this->w;
     $canvas = imagecreatetruecolor($canvasWidth, $canvasHeight);
     imagefill($canvas, 0, 0, imagecolorallocatealpha($canvas, 0, 0, 0, 127));
     $this->addBorders($canvas, $originalWidth, $originalHeight, $canvasHeight, $canvasWidth);
     $this->addCorners($canvas, $canvasHeight, $canvasWidth);
     imagecopyresampled($canvas, $image->getResource(), $this->w, $this->w, 0, 0, $originalWidth, $originalHeight, $originalWidth, $originalHeight);
     return $canvas;
 }
예제 #2
0
 /**
  * @param Image $image
  * @param string $text
  * @param Coords $coords
  * @param AddTextParams $params
  */
 public function addText(Image $image, $text, Coords $coords, AddTextParams $params)
 {
     $placeWidth = $params->width === null ? $image->getWidth() - $coords->getX() : $params->width;
     $this->lastCoords = $coords;
     $lines = $this->getLines($text, $placeWidth, $params);
     if (count($lines) == 0) {
         return;
     }
     if ($params->expandSide == AddTextParams::EXPAND_HEIGHT) {
         $newHeight = $coords->getY() + count($lines) * $params->lineHeight;
         if ($newHeight > $image->getHeight()) {
             $image->resizeCanvasHeight($newHeight);
         }
     }
     foreach ($lines as $line) {
         $this->renderLine($image, $params, $line, $placeWidth);
     }
 }
예제 #3
0
 /**
  * @param resource $canvas
  * @param Image $image
  */
 private function addReflection($canvas, Image $image)
 {
     $width = $image->getWidth();
     $start = $image->getHeight();
     $end = imagesy($canvas);
     $imageResource = $image->getResource();
     $range = $end - $start;
     $opacityDiffPerLine = ($this->endTransparency - $this->startTransparency) / $range;
     $opacity = $this->startTransparency;
     for ($y = 0; $y < $range; ++$y, $opacity += $opacityDiffPerLine) {
         $sourceLineIndex = $start - $y - 1;
         $targetLineIndex = $start + $y;
         for ($x = 0; $x < $width; ++$x) {
             // found rgb in source image
             $rgb = imagecolorsforindex($imageResource, imagecolorat($imageResource, $x, $sourceLineIndex));
             // copy rgb from source image to canvas with opacity
             $color = imagecolorallocatealpha($canvas, $rgb['red'], $rgb['green'], $rgb['blue'], round(127 * $opacity));
             imagesetpixel($canvas, $x, $targetLineIndex, $color);
         }
     }
 }
예제 #4
0
파일: Image.php 프로젝트: jelito/imager
 /**
  * @param Image $image
  * @param Coords $coords
  */
 public function addImage(Image $image, Coords $coords)
 {
     imagecopy($this->resource, $image->getResource(), $coords->getX(), $coords->getY(), 0, 0, $image->getWidth(), $image->getHeight());
 }