/** * @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; }
/** * @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); } } }
/** * @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()); }
/** * @param Image $image * @param AddTextParams $params * @param string $text * @param int $placeWidth */ private function renderLine(Image $image, AddTextParams $params, $text, $placeWidth) { $leftPadding = $this->getLeftPadding($params, $text, $placeWidth); // velikost radku je 30, velikost pisma je 16, takze bude 7px nad a pod textem $space = round(($params->lineHeight - $params->size) / 2); imagettftext($image->getResource(), $params->size, 0, $this->lastCoords->getX() + $leftPadding, $this->lastCoords->getY() + $params->lineHeight - $space, $params->color, $params->fontFile, $text); $this->lastCoords->addY($params->lineHeight); }