public function draw(OsuSignature $signature) { parent::draw($signature); $flag = $this->getFlag($signature->getUser()); if ($flag) { $flag->resizeImage($this->getWidth(), $this->getHeight(), Imagick::FILTER_CATROM, 1); if (isset($_GET['flagshadow'])) { $shadow = $flag->clone(); $shadow->setImageBackgroundColor(new ImagickPixel('black')); $shadow->shadowImage(50, 3, 0, 0); $signature->getCanvas()->compositeImage($shadow, \Imagick::COMPOSITE_DEFAULT, $this->x - 6, $this->y - 6); } if (isset($_GET['flagstroke'])) { $flagStroke = new \ImagickDraw(); $flagStroke->setFillColor("#FFFFFFEE"); $flagStroke->roundRectangle($this->x - 1, $this->y - 1, $this->x - 1 + ($this->getWidth() + 1), $this->y - 1 + ($this->getHeight() + 1), 1, 1); $signature->getCanvas()->drawImage($flagStroke); } $signature->getCanvas()->compositeImage($flag, Imagick::COMPOSITE_DEFAULT, $this->x, $this->y); } }
public function draw(OsuSignature $signature) { parent::draw($signature); $avatar = $this->getAvatar($signature->getUser()); if ($avatar) { $fitByWidth = $this->getWidth() / $avatar->getImageWidth() < $this->getHeight() / $avatar->getImageHeight() ? true : false; if ($fitByWidth) { $avatar->thumbnailImage($this->getWidth(), 0, false); } else { $avatar->thumbnailImage(0, $this->getHeight(), false); } $avatarXOffset = ($this->getWidth() - $avatar->getImageWidth()) / 2; $avatarYOffset = ($this->getHeight() - $avatar->getImageHeight()) / 2; /*$avatar->resizeImage( $this->getWidth(), $this->get Height(), 1 Imagick::FILTER_CATROM );*/ $avatarRounding = isset($_GET['avatarrounding']) ? max((int) $_GET['avatarrounding'], 0) : $this->rounding; $avatar->setImageAlphaChannel(Imagick::ALPHACHANNEL_SET); $roundImage = new Imagick(); $roundImage->newPseudoImage($this->getWidth(), $this->getHeight(), 'canvas:transparent'); $roundMask = new ImagickDraw(); $roundMask->setFillColor(new ImagickPixel('black')); $roundMask->roundRectangle(0, 0, $avatar->getImageWidth() - 1, $avatar->getImageHeight() - 1, $avatarRounding, $avatarRounding); $roundImage->drawImage($roundMask); $roundImage->setImageFormat('png'); $avatar->compositeImage($roundImage, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA); $signature->getCanvas()->compositeImage($avatar, Imagick::COMPOSITE_DEFAULT, $this->x + $avatarXOffset, $this->y + $avatarYOffset); } }
/** * Draw a rounded rectangle on the image. * * @param int $x * @param int $y * @param int $w * @param int $h * @param int $rx * @param int $ry * @return Imagick */ public function roundedRectangle($x, $y, $w, $h = null, $rx = 10, $ry = null) { $x2 = $x + $w; $y2 = $y + (null === $h ? $w : $h); if (null === $ry) { $ry = $rx; } $draw = new \ImagickDraw(); if (null !== $this->fillColor) { $draw->setFillColor($this->image->getColor($this->fillColor, $this->opacity)); } if ($this->strokeWidth > 0) { $draw->setStrokeColor($this->image->getColor($this->strokeColor, $this->opacity)); $draw->setStrokeWidth($this->strokeWidth); } $draw->roundRectangle($x, $y, $x2, $y2, $rx, $ry); $this->image->resource()->drawImage($draw); return $this; }
/** * Draw a rounded rectangle. * * @param integer $x The left x-coordinate of the rectangle. * @param integer $y The top y-coordinate of the rectangle. * @param integer $width The width of the rectangle. * @param integer $height The height of the rectangle. * @param integer $round The width of the corner rounding. * @param string $color The line color of the rectangle. * @param string $fill The color to fill the rounded rectangle with. */ public function roundedRectangle($x, $y, $width, $height, $round, $color, $fill) { $draw = new ImagickDraw(); $draw->setStrokeColor(new ImagickPixel($color)); $draw->setFillColor(new ImagickPixel($fill)); $draw->roundRectangle($x, $y, $x + $width, $y + $height, $round, $round); try { $res = $this->_imagick->drawImage($draw); } catch (ImagickException $e) { throw new Horde_Image_Exception($e); } $draw->destroy(); }
function roundRectangle($strokeColor, $fillColor, $backgroundColor, $startX, $startY, $endX, $endY, $roundX, $roundY) { $draw = new \ImagickDraw(); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); $draw->setStrokeOpacity(1); $draw->setStrokeWidth(2); $draw->roundRectangle($startX, $startY, $endX, $endY, $roundX, $roundY); $imagick = new \Imagick(); $imagick->newImage(500, 500, $backgroundColor); $imagick->setImageFormat("png"); $imagick->drawImage($draw); header("Content-Type: image/png"); echo $imagick->getImageBlob(); }
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)); }
/** * Draws the stroke over the whole card * * @param string $hexColour [Hexadecimal colour value for the card stroke] */ public function drawFinalStroke($hexColour) { $cardStrokeImage = new Imagick(); $cardStrokeImage->newPseudoImage($this->canvas->getImageWidth(), $this->canvas->getImageHeight(), 'canvas:transparent'); $cardStroke = new ImagickDraw(); $cardStroke->setFillColor(new ImagickPixel($hexColour)); $cardStroke->roundRectangle(self::SIG_MARGIN + self::SIG_STROKE_WIDTH / 2, self::SIG_MARGIN + self::SIG_STROKE_WIDTH / 2, $this->baseWidth + self::SIG_MARGIN - 1 - self::SIG_STROKE_WIDTH / 2, $this->baseHeight + self::SIG_MARGIN - 1 - self::SIG_STROKE_WIDTH / 2, self::SIG_OUTER_ROUNDING * 2, self::SIG_OUTER_ROUNDING * 2); $cardStrokeImage->drawImage($cardStroke); $roundImage = new Imagick(); $roundImage->newPseudoImage($this->canvas->getImageWidth(), $this->canvas->getImageHeight(), 'canvas:transparent'); $roundMask = new ImagickDraw(); $roundMask->setFillColor(new ImagickPixel('black')); $roundMask->roundRectangle(self::SIG_MARGIN + self::SIG_STROKE_WIDTH * 2, self::SIG_MARGIN + self::SIG_STROKE_WIDTH * 2, $this->baseWidth + self::SIG_MARGIN - self::SIG_STROKE_WIDTH * 2 - 1, $this->baseHeight + self::SIG_MARGIN - self::SIG_STROKE_WIDTH * 2 - 1, self::SIG_ROUNDING, self::SIG_ROUNDING); $roundImage->drawImage($roundMask); $cardStrokeImage->compositeImage($roundImage, Imagick::COMPOSITE_DSTOUT, 0, 0); $this->canvas->compositeImage($cardStrokeImage, \Imagick::COMPOSITE_DEFAULT, 0, 0); }
/** * Build image * @access protected * @return Imagick */ protected function _buildImage() { $canvas = new Imagick(); $canvas->newImage($this->_width, $this->_height, 'none'); $draw = new ImagickDraw(); //drawing Background $draw->setFillColor(new ImagickPixel($this->_theme->bgColor)); $draw->roundRectangle(0, 0, $this->_width - 1, $this->_height - 1, 5, 5); //drawing Title and Description $this->_addTextToDraw($draw, $this->_theme->titleColor, $this->_theme->titleFont, $this->_theme->titleFontSize, 84, $this->_theme->titleYPos, $this->_title); $this->_addTextToDraw($draw, $this->_theme->textColor, $this->_theme->textFont, $this->_theme->textFontSize, 84, $this->_theme->descYPos, $this->_description); //drawing Reward if (!empty($this->_reward)) { $this->_addTextToDraw($draw, $this->_theme->textColor, $this->_theme->textFont, $this->_theme->textFontSize, 84, $this->_theme->rewardYPos, $this->_reward); } $canvas->drawImage($draw); //drawing pix (if not unlocked, set black and white) $expired = new Imagick($this->_pix); if ($this->_state != 'unlocked') { $expired->modulateImage(100, 0, 100); } $canvas->compositeImage($expired, imagick::COMPOSITE_OVER, 4, 4); //if expired, draw the expired logo if ($this->_state == 'expired') { $expired = new Imagick(dirname(__FILE__) . '/extra/expired.png'); $canvas->compositeImage($expired, imagick::COMPOSITE_OVER, 0, 0); } return $canvas; }