本文整理匯總了PHP中Imagine\Image\ImagineInterface::font方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImagineInterface::font方法的具體用法?PHP ImagineInterface::font怎麽用?PHP ImagineInterface::font使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagine\Image\ImagineInterface
的用法示例。
在下文中一共展示了ImagineInterface::font方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setFontProperties
/**
* Set properties for text drawing on the image.
*
* @param $fontFile string path to the font file on server
* @param $size int font size to use
* @param $color string font color to use in hex format
*
* @return null
*/
public function setFontProperties($fontFile, $size, $color)
{
if (empty($this->_palette)) {
$this->_palette = new \Imagine\Image\Palette\RGB();
}
$this->_font = $this->_instance->font($fontFile, $size, $this->_palette->color($color));
}
示例2: getImagineImage
public function getImagineImage(ImagineInterface $imagine, FontCollection $fontCollection, $width, $height)
{
$fontPath = $fontCollection->getFontById($this->font)->getPath();
if ($this->getAbsoluteSize() !== null) {
$fontSize = $this->getAbsoluteSize();
} elseif ($this->getRelativeSize() !== null) {
$fontSize = (int) $this->getRelativeSize() / 100 * $height;
} else {
throw new \LogicException('Either relative or absolute watermark size must be set!');
}
if (true || !class_exists('ImagickDraw')) {
// Fall back to ugly image.
$palette = new \Imagine\Image\Palette\RGB();
$font = $imagine->font($fontPath, $fontSize, $palette->color('#000'));
$box = $font->box($this->getText());
$watermarkImage = $imagine->create($box, $palette->color('#FFF'));
$watermarkImage->draw()->text($this->text, $font, new \Imagine\Image\Point(0, 0));
} else {
// CURRENTLY DISABLED.
// Use nicer Imagick implementation.
// Untested!
// @todo Test and implement it!
$draw = new \ImagickDraw();
$draw->setFont($fontPath);
$draw->setFontSize($fontSize);
$draw->setStrokeAntialias(true);
//try with and without
$draw->setTextAntialias(true);
//try with and without
$draw->setFillColor('#fff');
$textOnly = new \Imagick();
$textOnly->newImage(1400, 400, "transparent");
//transparent canvas
$textOnly->annotateImage($draw, 0, 0, 0, $this->text);
//Create stroke
$draw->setFillColor('#000');
//same as stroke color
$draw->setStrokeColor('#000');
$draw->setStrokeWidth(8);
$strokeImage = new \Imagick();
$strokeImage->newImage(1400, 400, "transparent");
$strokeImage->annotateImage($draw, 0, 0, 0, $this->text);
//Composite text over stroke
$strokeImage->compositeImage($textOnly, \Imagick::COMPOSITE_OVER, 0, 0, \Imagick::CHANNEL_ALPHA);
$strokeImage->trimImage(0);
//cut transparent border
$watermarkImage = $imagine->load($strokeImage->getImageBlob());
//$strokeImage->resizeImage(300,0, \Imagick::FILTER_CATROM, 0.9, false); //resize to final size
}
return $watermarkImage;
}
示例3: wrap
/**
*
* @param int $fontSize
* @param int $angle
* @param string $fontFace
* @param string $string
* @param int $width
* @return array
*/
protected static function wrap(ImagineInterface $imagine, $fontSize, $angle, $fontFace, $string, $width)
{
static $palette;
if (null === $palette) {
$palette = new RGB();
}
// str 'Op' used to calculate linespace
$font = $imagine->font($fontFace, $fontSize, $palette->color("000000", 0));
$testbox = $font->box("0p", $angle);
$height = $testbox->getHeight();
$testbox = $font->box("M", $angle);
// 1 em
$dy = $testbox->getHeight();
$toth = 0;
$ret = [];
foreach (explode("\n", $string) as $lig) {
if ($lig == '') {
$ret[] = ['w' => 0, 'h' => $dy, 't' => ''];
$toth += $dy;
} else {
$twords = [];
$iword = -1;
$lastc = '';
$length = strlen($lig);
for ($i = 0; $i < $length; $i++) {
$c = $lig[$i];
if ($iword == -1 || ctype_space($c) && !ctype_space($lastc)) {
$twords[++$iword] = [$part = 0 => '', 1 => ''];
}
if (!ctype_space($c) && $part == 0) {
$part++;
}
$twords[$iword][$part] .= $lastc = $c;
}
if ($iword >= 0 && $twords[0][1] != '') {
$buff = '';
$lastw = $lasth = 0;
foreach ($twords as $i => $wrd) {
$test = $buff . $wrd[0] . $wrd[1];
$testbox = $font->box($test, $angle);
$w = $testbox->getWidth();
$h = $testbox->getHeight();
if ($i > 0 && $testbox->getWidth() > $width) {
$ret[] = ['w' => $lastw, 'h' => $lasth, 't' => $buff];
$toth += $lasth;
$buff = $wrd[1];
} else {
$buff = $test;
}
$lastw = $w;
$lasth = $h;
}
if ($buff != '') {
$ret[] = ['w' => $lastw, 'h' => $lasth, 't' => $buff];
$toth += $lasth;
}
}
}
}
return ['toth' => $toth, 'l' => $ret, 'h' => $height, 'dy' => $dy];
}
示例4: setFont
/**
* Return full font path
*
* @param ImagineInterface $imagine
* @param string $font
* @param integer $size
* @param string $color
*
* @return string
*/
protected function setFont(ImagineInterface $imagine, $font, $size, $color = 'ffffff')
{
return $imagine->font($this->getResourceDir() . '/fonts/' . $font, $size, new Color($color));
}