/** * Generate a new image resource var * * @param integer $width * @param integer $height * @param string $color * @param integer $opacity * * @return resource */ public static function generateImage($width = 100, $height = 100, $color = 'ffffff', $opacity = 127) { $RGBColors = ImageWorkshopLib::convertHexToRGB($color); $image = imagecreatetruecolor($width, $height); imagesavealpha($image, true); $color = imagecolorallocatealpha($image, $RGBColors['R'], $RGBColors['G'], $RGBColors['B'], $opacity); imagefill($image, 0, 0, $color); return $image; }
/** * Add a text on the background image of the layer using a font localized at $fontPath * Return the text coordonates * * @param string $text * @param integer $fontPath * @param integer $fontSize * @param string $color * @param integer $positionX * @param integer $positionY * @param integer $fontRotation * * @return array */ public function write($text, $fontPath, $fontSize = 13, $color = 'ffffff', $positionX = 0, $positionY = 0, $fontRotation = 0) { if (!file_exists($fontPath)) { throw new ImageWorkshopLayerException('Can\'t find a font file at this path : "' . $fontPath . '".', static::ERROR_FONT_NOT_FOUND); } $RGBTextColor = ImageWorkshopLib::convertHexToRGB($color); $textColor = imagecolorallocate($this->image, $RGBTextColor['R'], $RGBTextColor['G'], $RGBTextColor['B']); return imagettftext($this->image, $fontSize, $fontRotation, $positionX, $positionY, $textColor, $fontPath, $text); }