function drawImage() { $strokeColor = 'black'; $fillColor = 'plum1'; $draw = new \ImagickDraw(); $draw->setStrokeOpacity(1); $draw->setStrokeColor($strokeColor); $draw->setStrokeWidth(1.2); $draw->setFont("../fonts/Arial.ttf"); $draw->setFontSize(64); $draw->setFillColor($fillColor); $draw->rotate(-12); $draw->annotation(140, 380, "c'est ne pas \nune Lorikeet!"); $imagick = new \Imagick(realpath("../imagick/images/lories/IMG_1599_480.jpg")); $imagick->setImageFormat("png"); $imagick->drawImage($draw); header("Content-Type: image/png"); echo $imagick->getImageBlob(); }
function rotate($strokeColor, $fillColor, $backgroundColor, $fillModifiedColor) { $draw = new \ImagickDraw(); $draw->setStrokeColor($strokeColor); $draw->setStrokeOpacity(1); $draw->setFillColor($fillColor); $draw->rectangle(200, 200, 300, 300); $draw->setFillColor($fillModifiedColor); $draw->rotate(15); $draw->rectangle(200, 200, 300, 300); $image = new \Imagick(); $image->newImage(500, 500, $backgroundColor); $image->setImageFormat("png"); $image->drawImage($draw); header("Content-Type: image/png"); echo $image->getImageBlob(); }
/** * Set and apply the text on the image * * @param string $string * @throws Exception * @return Imagick */ public function text($string) { $draw = new \ImagickDraw(); // Set the font if passed if (null !== $this->font) { if (!$draw->setFont($this->font)) { throw new Exception('Error: That font is not recognized by the Imagick extension.'); } // Else, attempt to set a basic, default system font } else { $fonts = $this->image->resource()->queryFonts(); if (in_array('Arial', $fonts)) { $this->font = 'Arial'; } else { if (in_array('Helvetica', $fonts)) { $this->font = 'Helvetica'; } else { if (in_array('Tahoma', $fonts)) { $this->font = 'Tahoma'; } else { if (in_array('Verdana', $fonts)) { $this->font = 'Verdana'; } else { if (in_array('System', $fonts)) { $this->font = 'System'; } else { if (in_array('Fixed', $fonts)) { $this->font = 'Fixed'; } else { if (in_array('system', $fonts)) { $this->font = 'system'; } else { if (in_array('fixed', $fonts)) { $this->font = 'fixed'; } else { if (isset($fonts[0])) { $this->font = $fonts[0]; } else { throw new Exception('Error: No default font could be found by the Imagick extension.'); } } } } } } } } } } $draw->setFont($this->font); $draw->setFontSize($this->size); $draw->setFillColor($this->image->getColor($this->fillColor, $this->opacity)); if (null !== $this->rotation) { $draw->rotate($this->rotation); } if (null !== $this->strokeColor) { $draw->setStrokeColor($this->image->getColor($this->strokeColor, $this->opacity)); $draw->setStrokeWidth((int) $this->strokeWidth); } $draw->annotation($this->x, $this->y, $string); $this->image->resource()->drawImage($draw); return $this; }
$strokeColor = "#ffffff"; $fillColor = "#0000ff"; $backgroundColor = "#000000"; $fillModifiedColor = "#00ffff"; $x1 = 100; $x2 = 400; $y1 = 230; $y2 = 280; $draw = new \ImagickDraw(); $draw->setStrokeColor($strokeColor); $draw->setStrokeOpacity(1); $draw->setFillColor($fillColor); $draw->rectangle($x1, $y1, $x2, $y2); $draw->setFillColor($fillModifiedColor); $draw->rotate(25); list($rx1, $ry1) = get($x1, $y1, 25); list($rx2, $ry2) = get($x2, $y2, 25); $draw->rectangle($rx1, $ry1, $rx2, $ry2); $image = new \Imagick(); $image->newImage(500, 500, $backgroundColor); $image->setImageFormat("png"); $image->drawImage($draw); header("Content-Type: image/png"); echo $image->getImageBlob(); function get($x, $y, $r) { $rx = $x - 250 + cos(deg2rad($r)) * 250 + sin(deg2rad($r)) * 250; $ry = $y - 250 + cos(deg2rad($r)) * 250 - sin(deg2rad($r)) * 250; return array($rx, $ry); }