function createEmailPic($jid, $email) { $cachefile = DOCUMENT_ROOT . '/cache/' . $jid . '_email.png'; if (file_exists(DOCUMENT_ROOT . '/cache/' . $jid . '_email.png')) { unlink(DOCUMENT_ROOT . '/cache/' . $jid . '_email.png'); } $draw = new ImagickDraw(); $draw->setFontSize(13); $draw->setGravity(Imagick::GRAVITY_CENTER); $canvas = new Imagick(); $metrics = $canvas->queryFontMetrics($draw, $email); $canvas->newImage($metrics['textWidth'], $metrics['textHeight'], "transparent", "png"); $canvas->annotateImage($draw, 0, 0, 0, $email); $canvas->setImageFormat('PNG'); $canvas->writeImage($cachefile); }
private function generateImage() { $this->generatedImage = new \Imagick(); $rgbBackgroundColor = $this->getBackgroundColor(); if (null === $rgbBackgroundColor) { $background = 'none'; } else { $background = new \ImagickPixel("rgb({$rgbBackgroundColor['0']},{$rgbBackgroundColor['1']},{$rgbBackgroundColor['2']})"); } $this->generatedImage->newImage($this->pixelRatio * 5, $this->pixelRatio * 5, $background, 'png'); // prepare color $rgbColor = $this->getColor(); $color = new \ImagickPixel("rgb({$rgbColor['0']},{$rgbColor['1']},{$rgbColor['2']})"); $draw = new \ImagickDraw(); $draw->setFillColor($color); // draw the content foreach ($this->getArrayOfSquare() as $lineKey => $lineValue) { foreach ($lineValue as $colKey => $colValue) { if (true === $colValue) { $draw->rectangle($colKey * $this->pixelRatio, $lineKey * $this->pixelRatio, ($colKey + 1) * $this->pixelRatio, ($lineKey + 1) * $this->pixelRatio); } } } $this->generatedImage->drawImage($draw); return $this; }
private function createImage() { /* Create Imagick object */ $this->Imagick = new \Imagick(); /* Create the ImagickPixel object (used to set the background color on image) */ $bg = new \ImagickPixel(); /* Set the pixel color to white */ $bg->setColor($this->bg_color); /* Create a drawing object and set the font size */ $ImagickDraw = new \ImagickDraw(); /* Set font and font size. You can also specify /path/to/font.ttf */ if ($this->font) { $ImagickDraw->setFont($this->font); } $ImagickDraw->setFontSize($this->font_size); /* Create new empty image */ $this->Imagick->newImage($this->image_width, $this->image_height, $bg); /* Write the text on the image */ $this->Imagick->annotateImage($ImagickDraw, $this->text_position_left, $this->text_position_top, 0, $this->getCaptchaText()); /* Add some swirl */ $this->Imagick->swirlImage(20); /* Create a few random lines */ $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height)); $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height)); $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height)); $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height)); $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height)); /* Draw the ImagickDraw object contents to the image. */ $this->Imagick->drawImage($ImagickDraw); /* Give the image a format */ $this->Imagick->setImageFormat($this->image_format); }
public function histogram() { for ($i = 0; $i <= 256; $i++) { $this->data[$i] = array('r' => 0, 'g' => 0, 'b' => 0, 'y' => 0); } $this->iterate('hist_prepare'); $maxPixelCount = 0; foreach ($this->data as $k => $v) { $maxPixelCount = max($maxPixelCount, $v['r'], $v['g'], $v['b'], $v['y']); } $this->img->newImage(512, 512, new ImagickPixel('white')); $this->img->setImageFormat('png'); $draw = new ImagickDraw(); for ($i = 0; $i < 257; $i++) { $draw->setStrokeColor('#ff0000'); $draw->line($i * 2, 512, $i * 2, 512 - $this->data[$i]['r'] / $maxPixelCount * 512); $draw->setStrokeColor('#00ff00'); $draw->line($i * 2, 512, $i * 2, 512 - $this->data[$i]['g'] / $maxPixelCount * 512); $draw->setStrokeColor('#0000ff'); $draw->line($i * 2, 512, $i * 2, 512 - $this->data[$i]['b'] / $maxPixelCount * 512); $draw->setStrokeColor('#aaaaaa'); $draw->line($i * 2, 512, $i * 2, 512 - $this->data[$i]['y'] / $maxPixelCount * 512); } $this->img->drawImage($draw); }
/** * Draws the background colour for the signature. * Note that this has no relation to {@link Card}s. * * @param $hexColour string Hexadecimal colour value */ protected function drawBackground($hexColour) { $background = new ImagickDraw(); $background->setFillColor($hexColour); $background->rectangle(0, 0, $this->canvas->getImageWidth(), $this->canvas->getImageHeight()); $this->canvas->drawImage($background); }
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; } }
/** * Draw line between points * Нарисовать линии между указанными точками * @param int $sx * @param int $sy * @param int $ex * @param int $ey */ public function drawLine($sx, $sy, $ex, $ey) { $draw = new \ImagickDraw(); $draw->setStrokeColor($this->black); $draw->setStrokeWidth(1); $draw->line($sx, $sy, $ex, $ey); $this->drawImage($draw); }
/** * Flood the image with a color fill. * * @param int $r * @param int $g * @param int $b * @return Imagick */ public function fill($r, $g, $b) { $draw = new \ImagickDraw(); $draw->setFillColor($this->image->getColor([(int) $r, (int) $g, (int) $b])); $draw->rectangle(0, 0, $this->image->getWidth(), $this->image->getHeight()); $this->image->resource()->drawImage($draw); return $this; }
/** * (non-PHPdoc) * @see Imagine\Image\FontInterface::box() */ public function box($string, $angle = 0) { $text = new \ImagickDraw(); $text->setFont($this->file); $text->setFontSize($this->size); $info = $this->imagick->queryFontMetrics($text, $string); $box = new Box($info['textWidth'], $info['textHeight']); return $box; }
/** * Draw current instance of line to given endpoint on given image * * @param Image $image * @param integer $x * @param integer $y * @return boolean */ public function applyToImage(Image $image, $x = 0, $y = 0) { $line = new \ImagickDraw(); $color = new Color($this->color); $line->setStrokeColor($color->getPixel()); $line->setStrokeWidth($this->width); $line->line($this->x, $this->y, $x, $y); $image->getCore()->drawImage($line); return true; }
/** * @param ImageInterface $image * @return Image */ public function draw($image) { // Localize vars $width = $image->getWidth(); $height = $image->getHeight(); $imagick = $image->getCore(); $draw = new \ImagickDraw(); $strokeColor = new \ImagickPixel($this->getColor()->getHexString()); $fillColor = new \ImagickPixel('rgba(0,0,0,0)'); $draw->setStrokeOpacity(1); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); list($x1, $y1) = $this->point1; list($x2, $y2) = $this->control; list($x3, $y3) = $this->point2; $draw->pathStart(); $draw->pathMoveToAbsolute($x1, $y1); $draw->pathCurveToQuadraticBezierAbsolute($x2, $y2, $x3, $y3); $draw->pathFinish(); // Render the draw commands in the ImagickDraw object $imagick->drawImage($draw); $type = $image->getType(); $file = $image->getImageFile(); return new Image($imagick, $file, $width, $height, $type); // Create new image with updated core }
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; }
/** * Draws some text on the handle * * @param Zend_Image_Adapter_ImageMagick $adapter Adapter * @param Zend_Image_Action_DrawText $textObject The object that with all info */ public function perform($adapter, Zend_Image_Action_DrawText $textObject) { // As of ZF2.0 / PHP5.3, this can be made static. $handle = $adapter->getHandle(); $color = new ImagickPixel('#000000'); // . $textObject->getColor()); $draw = new ImagickDraw(); $draw->annotation($textObject->getOffsetX(), $textObject->getOffsetY(), $textObject->getText()); $handle->drawImage($draw); return $handle; }
/** * @param Image $image * * @return Image */ public function draw($image) { $strokeColor = new \ImagickPixel($this->getColor()->getHexString()); $draw = new \ImagickDraw(); $draw->setStrokeColor($strokeColor); $draw->setStrokeWidth($this->thickness); list($x1, $y1) = $this->point1; list($x2, $y2) = $this->point2; $draw->line($x1, $y1, $x2, $y2); $image->getCore()->drawImage($draw); return $image; }
/** * Draws one pixel to a given image * * @param Intervention\Image\Image $image * @return boolean */ public function execute($image) { $color = $this->argument(0)->required()->value(); $color = new Color($color); $x = $this->argument(1)->type('integer')->required()->value(); $y = $this->argument(2)->type('integer')->required()->value(); // prepare pixel $draw = new \ImagickDraw(); $draw->setFillColor($color->getPixel()); $draw->point($x, $y); // apply pixel return $image->getCore()->drawImage($draw); }
public function colorize($color, $alpha = 1) { $draw = new ImagickDraw(); $draw->setFillColor($color); if (is_float($alpha)) { $draw->setFillAlpha($alpha); } $geometry = $this->getImageGeometry(); $width = $geometry['width']; $height = $geometry['height']; $draw->rectangle(0, 0, $width, $height); $this->drawImage($draw); }
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"); }
protected function getImage() { $image = new \Imagick(); $image->newImage(2, 2, new \ImagickPixel('white')); $draw = new \ImagickDraw(); $draw->setFillColor(new \ImagickPixel('black')); $draw->color(0, 1, \Imagick::PAINT_POINT); $draw2 = new \ImagickDraw(); $draw2->setFillColor(new \ImagickPixel('black')); $draw2->color(1, 1, \Imagick::PAINT_POINT); $image->drawImage($draw); $image->drawimage($draw2); $image->setformat('png'); return $image; }
function AboveText() { $abovetextimage = new Imagick(); $draw = new ImagickDraw(); $pixel = new ImagickPixel('transparent'); $abovetextimage->newImage(600, 600, $pixel); $draw->setFillColor('black'); $draw->setFont('Bookman-DemiItalic'); $draw->setFontSize(20); $myfirstName = explode(" ", $this->{$userName}); $fname = $myfirstName[0]; $abovetextimage->annotateImage($draw, 5, 20, 0, "{$this}->{$name} has a secret crush on {$fname}"); $abovetextimage->setImageFormat('png'); $abovetextimage->writeImage("abovetext.png"); $this->{$aboveText} = imagecreatefrompng("abovetext.png"); }
/** * Creates a new Label component. * * @param OsuSignature $signature The base signature * @param int $x The X position of this label * @param int $y The Y position of this label * @param string $text The text of this label * @param string $font The font to use for this label; can be a string or the constants defined in {@link ComponentLabel} * @param string $colour The colour of the text of the label * @param int $fontSize The size of the font of the label * @param int $textAlignment The text alignment * @param int $width Width of the label, set to -1 to use the text size, anything bigger can be used to spoof the component system. -2 makes the component sizeless * @param int $height Height of the label, set to -1 to use the text size, anything bigger can be used to spoof the component system */ public function __construct(OsuSignature $signature, $x = 0, $y = 0, $text, $font = self::FONT_REGULAR, $colour = '#555555', $fontSize = 14, $textAlignment = Imagick::ALIGN_UNDEFINED, $width = -1, $height = -1) { parent::__construct($signature, $x, $y); $this->text = $text; $this->font = $font; $this->colour = $colour; $this->fontSize = $fontSize; $this->textAlignment = $textAlignment; $this->width = $width; $this->height = $height; $this->drawSettings = new ImagickDraw(); $this->drawSettings->setFont(self::FONT_DIRECTORY . $font); $this->drawSettings->setFontSize($fontSize); $this->drawSettings->setTextAlignment($textAlignment); $this->drawSettings->setFillColor($colour); $this->usesSpace = $width != -2; if ($width <= -1 || $height <= -1) { $tempImg = new Imagick(); $metrics = $tempImg->queryFontMetrics($this->drawSettings, $this->text); $this->width = $width <= -1 ? $metrics['textWidth'] : $width; // yeah i have to do some bullshit $this->actualWidth = $metrics['textWidth']; $this->height = $metrics['boundingBox']['y2'] - $this->y; } }
/** * @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; }
/** * Add border * @param integer $width Border width * @param string $color Border color * @return Imagick */ public function border($width, $color) { $border = new \ImagickDraw(); $border->setFillColor('none'); $border->setStrokeColor(new \ImagickPixel($color)); $border->setStrokeWidth($width); $widthPart = $width / 2; $border->line(0, 0 + $widthPart, $this->width, 0 + $widthPart); $border->line(0, $this->height - $widthPart, $this->width, $this->height - $widthPart); $border->line(0 + $widthPart, 0, 0 + $widthPart, $this->height); $border->line($this->width - $widthPart, 0, $this->width - $widthPart, $this->height); $this->image->drawImage($border); return $this; }
public function build() { // Prepage image $this->_canvas = new Imagick(); $this->_canvas->newImage(self::WIDTH, self::HEIGHT, new ImagickPixel("white")); $color['line'] = new ImagickPixel("rgb(216, 76, 64)"); $color['text'] = new ImagickPixel("rgb(16, 35, 132)"); $color['karma'] = new ImagickPixel("rgb(116, 194, 98)"); $color['force'] = new ImagickPixel("rgb(37, 168, 255)"); $color['bottom_bg'] = new ImagickPixel("rgb(255, 244, 224)"); $color['bg'] = new ImagickPixel("white"); $color['neutral'] = new ImagickPixel("rgb(200, 200, 200)"); $color['habr'] = new ImagickPixel("rgb(83, 121, 139)"); // Prepare canvas for drawing main graph $draw = new ImagickDraw(); $draw->setStrokeAntialias(true); $draw->setStrokeWidth(2); // Prepare values for drawing main graph define('PADDING', 10); // Draw bottom bg define('TOP_SPACER', 10); $draw = new ImagickDraw(); $draw->setFillColor($color['bg']); $draw->setStrokeColor($color['habr']); $draw->polyline(array(array('x' => 0, 'y' => 0), array('x' => self::WIDTH - 1, 'y' => 0), array('x' => self::WIDTH - 1, 'y' => self::HEIGHT - 1), array('x' => 0, 'y' => self::HEIGHT - 1), array('x' => 0, 'y' => 0))); $this->_canvas->drawImage($draw); $draw->destroy(); // Draw texts $draw = new ImagickDraw(); $draw->setTextAlignment(Imagick::ALIGN_CENTER); $draw->setTextAntialias(true); $draw->setFillColor($color['karma']); $draw->polyline(array(array('x' => 1, 'y' => 1), array('x' => self::WIDTH / 2, 'y' => 1), array('x' => self::WIDTH / 2, 'y' => self::HEIGHT - 2), array('x' => 1, 'y' => self::HEIGHT - 2), array('x' => 1, 'y' => 1))); $draw->setFillColor($color['bg']); $draw->setFontSize(11); $draw->setFont(realpath('stuff/consolab.ttf')); $draw->annotation(self::WIDTH / 4, 11, sprintf('%01.2f', $this->_karma)); $draw->setFillColor($color['force']); $draw->polyline(array(array('x' => self::WIDTH / 2 + 1, 'y' => 1), array('x' => self::WIDTH - 2, 'y' => 1), array('x' => self::WIDTH - 2, 'y' => self::HEIGHT - 2), array('x' => self::WIDTH / 2 + 1, 'y' => self::HEIGHT - 2), array('x' => self::WIDTH / 2 + 1, 'y' => 1))); $draw->setFillColor($color['bg']); $draw->annotation(self::WIDTH / 4 * 3, 11, sprintf('%01.2f', $this->_habraforce)); $this->_canvas->drawImage($draw); $draw->destroy(); return true; }
function getImageHistogram($imagePath) { $backgroundColor = 'black'; $draw = new \ImagickDraw(); $draw->setStrokeWidth(0); //make the lines be as thin as possible $imagick = new \Imagick(); $imagick->newImage(500, 500, $backgroundColor); $imagick->setImageFormat("png"); $imagick->drawImage($draw); $histogramWidth = 256; $histogramHeight = 100; // the height for each RGB segment $imagick = new \Imagick(realpath($imagePath)); //Resize the image to be small, otherwise PHP tends to run out of memory //This might lead to bad results for images that are pathologically 'pixelly' $imagick->adaptiveResizeImage(200, 200, true); $histogramElements = $imagick->getImageHistogram(); $histogram = new \Imagick(); $histogram->newpseudoimage($histogramWidth, $histogramHeight * 3, 'xc:black'); $histogram->setImageFormat('png'); $getMax = function ($carry, $item) { if ($item > $carry) { return $item; } return $carry; }; $colorValues = ['red' => getColorStatistics($histogramElements, \Imagick::COLOR_RED), 'lime' => getColorStatistics($histogramElements, \Imagick::COLOR_GREEN), 'blue' => getColorStatistics($histogramElements, \Imagick::COLOR_BLUE)]; $max = array_reduce($colorValues['red'], $getMax, 0); $max = array_reduce($colorValues['lime'], $getMax, $max); $max = array_reduce($colorValues['blue'], $getMax, $max); $scale = $histogramHeight / $max; $count = 0; foreach ($colorValues as $color => $values) { $draw->setstrokecolor($color); $offset = ($count + 1) * $histogramHeight; foreach ($values as $index => $value) { $draw->line($index, $offset, $index, $offset - $value * $scale); } $count++; } $histogram->drawImage($draw); header("Content-Type: image/png"); echo $histogram; }
function a0nCRQ($msg, $padx, $pady, $bc, $fc, $tc) { $im = new Imagick(); $idraw = new ImagickDraw(); $idraw->setFontSize(30); $idraw->setFont('MyriadPro-Regular.otf'); $idraw->setGravity(Imagick::GRAVITY_CENTER); $metrics = $im->queryFontMetrics($idraw, $msg); $im->newPseudoImage($metrics["textWidth"] + $padx * 2, $metrics["textHeight"] + $pady * 2, "xc:none"); $idraw->setFillColor($fc); $idraw->setStrokeColor($bc); $idraw->roundrectangle(0, 0, $metrics["textWidth"] + $padx * 2 - 1, $metrics["textHeight"] + $pady * 2 - 1, 10, 10); $idraw->setFillColor($tc); $idraw->setStrokeColor($tc); $idraw->annotation(0, 0, $msg); $im->drawImage($idraw); return $im; }
function TextOverlay() { $textimage = new Imagick(); $draw = new ImagickDraw(); $pixel = new ImagickPixel('transparent'); /* New image */ $textimage->newImage(600, 600, $pixel); /* Black text */ $draw->setFillColor('blue'); /* Font properties */ $draw->setFont('Bookman-DemiItalic'); $draw->setFontSize(20); /* Create text */ $textimage->annotateImage($draw, 5, 20, 0, "{$name} has a secret CRUSH on YOU!"); /* Give image a format */ $textimage->setImageFormat('png'); $textimage->writeImage("rounded3.png"); $top_image3 = imagecreatefrompng("rounded3.png"); }
/** * Draws an arc on the handle * * @param Zend_Image_Adapter_ImageMagick $handle The handle on which the ellipse is drawn * @param Zend_Image_Action_DrawEllipse $ellipseObject The object that with all info */ public function perform(Zend_Image_Adapter_ImageMagick $adapter, Zend_Image_Action_DrawArc $arcObject) { $draw = new ImagickDraw(); $color = (string) $arcObject->getFillColor(); $draw->setStrokeColor($color); $location = $arcObject->getLocation($adapter); $cx = $location->getX(); $cy = $location->getY(); $width = $arcObject->getWidth(); $height = $arcObject->getHeight(); $sx = $cx - $width / 2; $ex = $cx + $width / 2; $sy = $cy - $height / 2; $ey = $cy + $height / 2; //$draw->arc($sx, $sy, $ex, $ey, $arcObject->getCutoutStart(), $arcObject->getCutoutEnd()); // $draw->arc($sx, $sy, $ex, $ey, 90, 315); $draw->arc($sx, $sy, $ex, $ey, 90, 270); $adapter->getHandle()->drawImage($draw); }
protected function _generateImage($text, $filePath) { $image = new Imagick(); $draw = new ImagickDraw(); $draw->setFont('lib/SwiftOtter/OpenSans-Regular.ttf'); $draw->setFontSize('13'); $metrics = $image->queryFontMetrics($draw, $text, false); $width = 100; $padding = 10; if (isset($metrics['textWidth'])) { $width = $metrics['textWidth'] + $padding * 2; } $image->newImage($width, 17, new ImagickPixel('#f98b25')); $draw->setFillColor('#ffffff'); $image->annotateImage($draw, $padding / 2 + 3, $padding + 3, 0, $text); $draw->setFillColor('#a04300'); $image->borderImage('#a04300', 1, 1); $image->setFormat('gif'); $image->writeImage($filePath); return $image; }
/** * Generates and dies with an image containing the heading and the text of the error. * * @param string $headingText The heading of the error. * @param string $errorText The text of the error. */ public function generate($headingText, $errorText) { $draw = new ImagickDraw(); $draw->setFillColor('#777777'); $draw->setFontSize(15); $draw->setFont('fonts/exo2bold.ttf'); $headingMetrics = $this->canvas->queryFontMetrics($draw, $headingText); $draw->setFont('fonts/exo2regular.ttf'); $textMetrics = $this->canvas->queryFontMetrics($draw, $errorText); $this->canvas->newImage(max($textMetrics['textWidth'], $headingMetrics['textWidth']) + 6, $textMetrics['textHeight'] + $headingMetrics['textHeight'] + 6, new ImagickPixel('white')); $this->canvas->annotateImage($draw, 3, $headingMetrics['textHeight'] * 2, 0, $errorText); $draw->setFont('fonts/exo2bold.ttf'); $draw->setFillColor('#333333'); $draw->setGravity(Imagick::GRAVITY_NORTH); $this->canvas->annotateImage($draw, 3, 3, 0, $headingText); $this->canvas->setImageFormat('png'); header('Content-Type: image/' . $this->canvas->getImageFormat()); header("Cache-Control: max-age=60"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60) . " GMT"); die($this->canvas); }
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 = Printer::IMG_DEFAULT; $this->printer->bitImage($escposImage, $size); }