本文整理匯總了PHP中Imagick::drawImage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::drawImage方法的具體用法?PHP Imagick::drawImage怎麽用?PHP Imagick::drawImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::drawImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: draw
public function draw(OsuSignature $signature)
{
if (empty($this->hexColour)) {
$this->hexColour = $signature->getHexColour();
}
$composite = new Imagick();
$composite->newPseudoImage($this->getWidth(), $this->getHeight(), "canvas:transparent");
// Background
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel("#555555"));
$draw->rectangle(0, 0, $this->getWidth(), $this->getHeight());
$composite->drawImage($draw);
// Main bar
$level = $signature->getUser()['level'];
$xp = $level - floor($level);
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel($this->hexColour));
$draw->rectangle(0, 0, $this->getWidth() * $xp, $this->getHeight());
$composite->drawImage($draw);
// Bar end glow
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel('#ffffff'));
$draw->setFillOpacity(0.35);
$draw->rectangle($this->getWidth() * $xp - $this->getHeight(), 0, $this->getWidth() * $xp, $this->getHeight());
$composite->drawImage($draw);
// Text draw & metrics
$textDraw = new ImagickDraw();
$textDraw->setFillColor(new ImagickPixel('#555555'));
$textDraw->setFontSize(12);
$textDraw->setFont(ComponentLabel::FONT_DIRECTORY . ComponentLabel::FONT_REGULAR);
$textDraw->setGravity(Imagick::GRAVITY_NORTHWEST);
$metrics = $composite->queryFontMetrics($textDraw, 'lv' . floor($level));
// Text white bg
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel('#ffffff'));
$draw->rectangle(($this->getWidth() - $metrics['textWidth']) / 2 - 2, 0, ($this->getWidth() + $metrics['textWidth']) / 2 + 1, $this->getHeight());
$composite->drawImage($draw);
// Rounding
$roundMask = new Imagick();
$roundMask->newPseudoImage($this->getWidth(), $this->getHeight(), "canvas:transparent");
$draw = new ImagickDraw();
$draw->setFillColor(new ImagickPixel("black"));
$draw->roundRectangle(0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $this->rounding, $this->rounding);
$roundMask->drawImage($draw);
$roundMask->setImageFormat('png');
$composite->compositeImage($roundMask, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA);
$signature->getCanvas()->compositeImage($composite, Imagick::COMPOSITE_DEFAULT, $this->x, $this->y);
// Level text
$signature->getCanvas()->annotateImage($textDraw, $this->x + ($this->getWidth() - $metrics['textWidth']) / 2, $this->y + ($this->getHeight() - $metrics['textHeight']) / 2 - 2, 0, 'lv' . floor($level));
}
示例2: createAvatarAutomatically
/**
* アバター自動生成処理
*
* @param Model $model ビヘイビア呼び出し元モデル
* @param array $user ユーザデータ配列
* @return mixed On success Model::$data, false on failure
* @throws InternalErrorException
*/
public function createAvatarAutomatically(Model $model, $user)
{
//imagickdraw オブジェクトを作成します
$draw = new ImagickDraw();
//文字色のセット
$draw->setfillcolor('white');
//フォントサイズを 160 に設定します
$draw->setFontSize(140);
//テキストを追加します
$draw->setFont(CakePlugin::path($model->plugin) . 'webroot' . DS . 'fonts' . DS . 'ipaexg.ttf');
$draw->annotation(19, 143, mb_substr(mb_convert_kana($user['User']['handlename'], 'KVA'), 0, 1));
//新しいキャンバスオブジェクトを作成する
$canvas = new Imagick();
//ランダムで背景色を指定する
$red1 = strtolower(dechex(mt_rand(3, 12)));
$red2 = strtolower(dechex(mt_rand(0, 15)));
$green1 = strtolower(dechex(mt_rand(3, 12)));
$green2 = strtolower(dechex(mt_rand(0, 15)));
$blue1 = strtolower(dechex(mt_rand(3, 12)));
$blue2 = strtolower(dechex(mt_rand(0, 15)));
$canvas->newImage(179, 179, '#' . $red1 . $red2 . $green1 . $green2 . $blue1 . $blue2);
//ImagickDraw をキャンバス上に描畫します
$canvas->drawImage($draw);
//フォーマットを PNG に設定します
$canvas->setImageFormat('png');
App::uses('TemporaryFolder', 'Files.Utility');
$folder = new TemporaryFolder();
$filePath = $folder->path . DS . Security::hash($user['User']['handlename'], 'md5') . '.png';
$canvas->writeImages($filePath, true);
return $filePath;
}
示例3: applyColorProfiles
/**
* this is to force RGB and to apply custom icc color profiles
*/
protected function applyColorProfiles()
{
if ($this->resource->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
$profiles = $this->resource->getImageProfiles('*', false);
// we're only interested if ICC profile(s) exist
$has_icc_profile = array_search('icc', $profiles) !== false;
// if it doesn't have a CMYK ICC profile, we add one
if ($has_icc_profile === false) {
$this->resource->profileImage('icc', self::getCMYKColorProfile());
}
// then we add an RGB profile
$this->resource->profileImage('icc', self::getRGBColorProfile());
$this->resource->setImageColorspace(Imagick::COLORSPACE_RGB);
}
}
// this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
// thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
// problem is described here: http://imagemagick.org/Usage/basics/#type
// and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
if ($this->resource->getimagetype() == Imagick::IMGTYPE_GRAYSCALE) {
$draw = new ImagickDraw();
$draw->setFillColor("red");
$draw->setfillopacity(0.001);
$draw->point(0, 0);
$this->resource->drawImage($draw);
}
}
示例4: renderImage
public function renderImage()
{
//Create a ImagickDraw object to draw into.
$draw = new \ImagickDraw();
$darkColor = new \ImagickPixel('brown');
//http://www.imagemagick.org/Usage/compose/#compose_terms
$draw->setStrokeColor($darkColor);
$draw->setFillColor('white');
$draw->setStrokeWidth(2);
$draw->setFontSize(72);
$draw->setStrokeOpacity(1);
$draw->setStrokeColor($darkColor);
$draw->setStrokeWidth(2);
$draw->setFont("../fonts/CANDY.TTF");
$draw->setFontSize(140);
$draw->setFillColor('none');
$draw->rectangle(0, 0, 1000, 300);
$draw->setFillColor('white');
$draw->annotation(50, 180, "Lorem Ipsum!");
$imagick = new \Imagick(realpath("images/TestImage.jpg"));
$draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
//Create an image object which the draw commands can be rendered into
$imagick = new \Imagick();
$imagick->newImage(1000, 300, "SteelBlue2");
$imagick->setImageFormat("png");
//Render the draw commands in the ImagickDraw object
//into the image.
$imagick->drawImage($draw);
//Send the image to the browser
header("Content-Type: image/png");
echo $imagick->getImageBlob();
}
示例5: makeImageOfCertification
public function makeImageOfCertification()
{
date_default_timezone_set('UTC');
$timeStamp = date('jS F Y');
$text = "CERTIFIED COPY" . "\n" . $this->serial . "\n" . $timeStamp;
$image = new \Imagick();
$draw = new \ImagickDraw();
$color = new \ImagickPixel('#000000');
$background = new \ImagickPixel("rgb(85, 196, 241)");
$draw->setFont($this->container->getParameter('assetic.write_to') . $this->container->get('templating.helper.assets')->getUrl('fonts/futura.ttf'));
$draw->setFontSize(24);
$draw->setFillColor($color);
$draw->setTextAntialias(true);
$draw->setStrokeAntialias(true);
//Align text to the center of the background
$draw->setTextAlignment(\Imagick::ALIGN_CENTER);
//Get information of annotation image
$metrics = $image->queryFontMetrics($draw, $text);
//Calc the distance(pixels) to move the sentences
$move = $metrics['textWidth'] / 2;
$draw->annotation($move, $metrics['ascender'], $text);
//Create an image of certification
$image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
$image->setImageFormat('png');
$image->drawImage($draw);
//Save an image temporary
$image->writeImage("cert_" . $this->serial . "_.png");
}
示例6: polygon
/**
* {@inheritdoc}
*/
public function polygon(array $coordinates, ColorInterface $color, $fill = false, $thickness = 1)
{
if (count($coordinates) < 3) {
throw new InvalidArgumentException(sprintf('Polygon must consist of at least 3 coordinates, %d given', count($coordinates)));
}
$points = array_map(function (PointInterface $p) {
return array('x' => $p->getX(), 'y' => $p->getY());
}, $coordinates);
try {
$pixel = $this->getColor($color);
$polygon = new \ImagickDraw();
$polygon->setStrokeColor($pixel);
$polygon->setStrokeWidth(max(1, (int) $thickness));
if ($fill) {
$polygon->setFillColor($pixel);
} else {
$polygon->setFillColor('transparent');
}
$polygon->polygon($points);
$this->imagick->drawImage($polygon);
$pixel->clear();
$pixel->destroy();
$polygon->clear();
$polygon->destroy();
} catch (\ImagickException $e) {
throw new RuntimeException('Draw polygon operation failed', $e->getCode(), $e);
}
return $this;
}
示例7: getBarcode
/**
* Return a PNG image representation of barcode (requires GD or Imagick library).
*
* @param string $code code to print
* @param string $type type of barcode:
* @param int $widthFactor Width of a single bar element in pixels.
* @param int $totalHeight Height of a single bar element in pixels.
* @param array $color RGB (0-255) foreground color for bar elements (background is transparent).
* @return \Imagick imagick object with barcode
* @public
*/
public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = array(0, 0, 0))
{
$barcodeData = $this->getBarcodeData($code, $type);
// calculate image size
$width = $barcodeData['maxWidth'] * $widthFactor;
$height = $totalHeight;
$colorForeground = new \imagickpixel('rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')');
$png = new \Imagick();
$png->newImage($width, $height, 'none', 'png');
$imageMagickObject = new \imagickdraw();
$imageMagickObject->setFillColor($colorForeground);
$imageMagickObject->setStrokeAntialias(false);
$imageMagickObject->setStrokeColor('rgb(255,255,255)');
// print bars
$positionHorizontal = 0;
foreach ($barcodeData['bars'] as $bar) {
$bw = round($bar['width'] * $widthFactor, 3);
$bh = round($bar['height'] * $totalHeight / $barcodeData['maxHeight'], 3);
if ($bar['drawBar']) {
$y = round($bar['positionVertical'] * $totalHeight / $barcodeData['maxHeight'], 3);
// draw a vertical bar
$imageMagickObject->rectangle($positionHorizontal, $y, $positionHorizontal + $bw, $y + $bh);
}
$positionHorizontal += $bw;
}
$png->drawImage($imageMagickObject);
return $png;
}
示例8: writeText
function writeText($text)
{
if ($this->printer == null) {
throw new LogicException("Not attached to a printer.");
}
if ($text == null) {
return;
}
$text = trim($text, "\n");
/* Create Imagick objects */
$image = new Imagick();
$draw = new ImagickDraw();
$color = new ImagickPixel('#000000');
$background = new ImagickPixel('white');
/* Create annotation */
//$draw -> setFont('Arial');// (not necessary?)
$draw->setFontSize(24);
// Size 21 looks good for FONT B
$draw->setFillColor($color);
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
$metrics = $image->queryFontMetrics($draw, $text);
$draw->annotation(0, $metrics['ascender'], $text);
/* Create image & draw annotation on it */
$image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
$image->setImageFormat('png');
$image->drawImage($draw);
//$image -> writeImage("test.png");
/* Save image */
$escposImage = new EscposImage();
$escposImage->readImageFromImagick($image);
$size = Escpos::IMG_DEFAULT;
$this->printer->bitImage($escposImage, $size);
}
示例9: image
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $format = "png", $quality = 85, $filename = FALSE, $save = TRUE, $print = false)
{
$imgH = count($frame);
$imgW = strlen($frame[0]);
$col[0] = new \ImagickPixel("white");
$col[1] = new \ImagickPixel("black");
$image = new \Imagick();
$image->newImage($imgW, $imgH, $col[0]);
$image->setCompressionQuality($quality);
$image->setImageFormat($format);
$draw = new \ImagickDraw();
$draw->setFillColor($col[1]);
for ($y = 0; $y < $imgH; $y++) {
for ($x = 0; $x < $imgW; $x++) {
if ($frame[$y][$x] == '1') {
$draw->point($x, $y);
}
}
}
$image->drawImage($draw);
$image->borderImage($col[0], $outerFrame, $outerFrame);
$image->scaleImage(($imgW + 2 * $outerFrame) * $pixelPerPoint, 0);
if ($save) {
if ($filename === false) {
throw new Exception("QR Code filename can't be empty");
}
$image->writeImages($filename, true);
}
if ($print) {
Header("Content-type: image/" . $format);
echo $image;
}
}
示例10: setColorspaceToRGB
/**
* @return $this
*/
public function setColorspaceToRGB()
{
$imageColorspace = $this->resource->getImageColorspace();
if ($imageColorspace == \Imagick::COLORSPACE_CMYK) {
if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
$profiles = $this->resource->getImageProfiles('*', false);
// we're only interested if ICC profile(s) exist
$has_icc_profile = array_search('icc', $profiles) !== false;
// if it doesn't have a CMYK ICC profile, we add one
if ($has_icc_profile === false) {
$this->resource->profileImage('icc', self::getCMYKColorProfile());
}
// then we add an RGB profile
$this->resource->profileImage('icc', self::getRGBColorProfile());
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
// we have to use SRGB here, no clue why but it works
} else {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
}
} else {
if ($imageColorspace == \Imagick::COLORSPACE_GRAY) {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
} else {
if (!in_array($imageColorspace, array(\Imagick::COLORSPACE_RGB, \Imagick::COLORSPACE_SRGB))) {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
} else {
// this is to handle embedded icc profiles in the RGB/sRGB colorspace
$profiles = $this->resource->getImageProfiles('*', false);
$has_icc_profile = array_search('icc', $profiles) !== false;
if ($has_icc_profile) {
try {
// if getImageColorspace() says SRGB but the embedded icc profile is CMYK profileImage() will throw an exception
$this->resource->profileImage('icc', self::getRGBColorProfile());
} catch (\Exception $e) {
\Logger::warn($e);
}
}
}
}
}
// this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
// thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
// problem is described here: http://imagemagick.org/Usage/basics/#type
// and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
$currentLocale = setlocale(LC_ALL, "0");
// this locale hack thing is also a hack for imagick
setlocale(LC_ALL, "");
// details see https://www.pimcore.org/issues/browse/PIMCORE-2728
$draw = new \ImagickDraw();
$draw->setFillColor("#ff0000");
$draw->setfillopacity(0.01);
$draw->point(floor($this->getWidth() / 2), floor($this->getHeight() / 2));
// place it in the middle of the image
$this->resource->drawImage($draw);
setlocale(LC_ALL, $currentLocale);
// see setlocale() above, for details ;-)
return $this;
}
示例11: drawText
/**
* @see wcf\system\image\adapter\IImageAdapter::drawText()
*/
public function drawText($string, $x, $y)
{
$draw = new \ImagickDraw();
$draw->setFillColor($this->color);
$draw->setTextAntialias(true);
// draw text
$draw->annotation($x, $y, $string);
$this->imagick->drawImage($draw);
}
示例12: analyzeImage
/**
* @param \Imagick $imagick
* @param int $graphWidth
* @param int $graphHeight
*/
public static function analyzeImage(\Imagick $imagick, $graphWidth = 255, $graphHeight = 127)
{
$sampleHeight = 20;
$border = 2;
$imagick->transposeImage();
$imagick->scaleImage($graphWidth, $sampleHeight);
$imageIterator = new \ImagickPixelIterator($imagick);
$luminosityArray = [];
foreach ($imageIterator as $row => $pixels) {
/* Loop through pixel rows */
foreach ($pixels as $column => $pixel) {
/* Loop through the pixels in the row (columns) */
/** @var $pixel \ImagickPixel */
if (false) {
$color = $pixel->getColor();
$luminosityArray[] = $color['r'];
} else {
$hsl = $pixel->getHSL();
$luminosityArray[] = $hsl['luminosity'];
}
}
/* Sync the iterator, this is important to do on each iteration */
$imageIterator->syncIterator();
break;
}
$draw = new \ImagickDraw();
$strokeColor = new \ImagickPixel('red');
$fillColor = new \ImagickPixel('red');
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(0);
$draw->setFontSize(72);
$draw->setStrokeAntiAlias(true);
$previous = false;
$x = 0;
foreach ($luminosityArray as $luminosity) {
$pos = $graphHeight - 1 - $luminosity * ($graphHeight - 1);
if ($previous !== false) {
/** @var $previous int */
//printf ( "%d, %d, %d, %d <br/>\n" , $x - 1, $previous, $x, $pos);
$draw->line($x - 1, $previous, $x, $pos);
}
$x += 1;
$previous = $pos;
}
$plot = new \Imagick();
$plot->newImage($graphWidth, $graphHeight, 'white');
$plot->drawImage($draw);
$outputImage = new \Imagick();
$outputImage->newImage($graphWidth, $graphHeight + $sampleHeight, 'white');
$outputImage->compositeimage($plot, \Imagick::COMPOSITE_ATOP, 0, 0);
$outputImage->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, $graphHeight);
$outputImage->borderimage('black', $border, $border);
$outputImage->setImageFormat("png");
App::cachingHeader("Content-Type: image/png");
echo $outputImage;
}
示例13: blueDiscAlpha
function blueDiscAlpha($width, $height)
{
$imagick = new Imagick();
$imagick->newImage($width, $height, 'none');
$draw = new ImagickDraw();
$draw->setStrokeOpacity(0);
$draw->setFillColor('blue');
$draw->circle(2 * $width / 3, 2 * $height / 3, $width - ($width / 3 - $width / 4), 2 * $height / 3);
$imagick->drawImage($draw);
return $imagick;
}
示例14: createDefaultLogo
public static function createDefaultLogo($path)
{
try {
$image = new \Imagick();
$image->newImage(90, 90, new \ImagickPixel("white"));
$draw = new \ImagickDraw();
$draw->setFillColor(new \ImagickPixel("#" . mt_rand(100000, 999999)));
$draw->ellipse(45, 45, 45, 45, 0, 360);
$image->drawImage($draw);
//$draw->setFillColor( new ImagickPixel( "#".mt_rand(100000, 999999) ) );#01C3EB
$draw->setFillColor(new \ImagickPixel("#418bc9"));
$draw->ellipse(45, 45, 20, 20, 0, 360);
$image->drawImage($draw);
$image->setImageFormat("png");
$image_name = 'image_' . time() . '.png';
$image->writeImage($path . $image_name);
return $image_name;
} catch (Exception $e) {
//echo $e->getMessage();
return false;
}
}
示例15: polyline
/**
* Draw a polyline (a non-closed, non-filled polygon) based on a
* set of vertices.
*
* @param array $vertices An array of x and y labeled arrays
* (eg. $vertices[0]['x'], $vertices[0]['y'], ...).
* @param string $color The color you want to draw the line with.
* @param string $width The width of the line.
*/
public function polyline($verts, $color, $width = 1)
{
$draw = new ImagickDraw();
$draw->setStrokeColor(new ImagickPixel($color));
$draw->setStrokeWidth($width);
$draw->setFillColor(new ImagickPixel('none'));
$draw->polyline($verts);
try {
$res = $this->_imagick->drawImage($draw);
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
$draw->destroy();
}