示例#1
0
 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();
 }
示例#2
0
 /**
  * アバター自動生成処理
  *
  * @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
0
function test_annotation(&$canvas)
{
    $draw = new ImagickDraw();
    $font = __DIR__ . '/php_imagick_tests/anonymous_pro_minus.ttf';
    $draw->setFont($font);
    $draw->setFontSize(40);
    $draw->annotation(50, 440, 'Yukkuri shiteitte ne!!!');
    $canvas->drawImage($draw);
}
示例#4
0
 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)");
     $color['transparent'] = new ImagickPixel("transparent");
     // Prepare canvas for drawing main graph
     $draw = new ImagickDraw();
     $draw->setStrokeAntialias(true);
     $draw->setStrokeWidth(2);
     // 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->setTextUnderColor($color['karma']);
     $draw->setFillColor($color['bg']);
     $draw->setFontSize(9 - 1 * ($this->_karma > 99 || $this->_habraforce > 99));
     $draw->setFont(realpath('stuff/consolab.ttf'));
     $draw->annotation(self::WIDTH / 2, 10, sprintf('%01.2f', $this->_karma));
     $draw->setTextUnderColor($color['force']);
     $draw->setFillColor($color['bg']);
     $draw->annotation(self::WIDTH / 2, 23, sprintf('%01.2f', $this->_habraforce));
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     return true;
 }
示例#5
0
 /**
  * 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;
 }
示例#6
0
 public function render($pDatas)
 {
     $im = new Imagick();
     $im->newImage(300, 300, "white", "png");
     $draw = new ImagickDraw();
     foreach ($pDatas as $key => $data) {
         if ($data->value == 0) {
             continue;
         }
         $draw->setFillColor('red');
         $draw->setstrokecolor('black');
         $draw->polygon($data->polygons);
         $draw->setFillColor('black');
         $draw->setFontSize(18);
         $draw->annotation($data->center['x'], $data->center['y'] + 9, $data->value);
     }
     $im->drawimage($draw);
     return $im;
 }
示例#7
0
 public function renderImage()
 {
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     $lightColor = new \ImagickPixel('LightCoral');
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor($lightColor);
     $draw->setStrokeWidth(2);
     $draw->setFontSize(36);
     $draw->setFont("../fonts/Arial.ttf");
     $draw->annotation(50, 50, "Lorem Ipsum!");
     $msg = "Danack";
     $xpos = 0;
     $ypos = 0;
     list($lines, $lineHeight) = wordWrapAnnotation($imagick, $draw, $msg, 140);
     for ($i = 0; $i < count($lines); $i++) {
         $imagick->annotateImage($draw, $xpos, $ypos + $i * $lineHeight, 0, $lines[$i]);
     }
     header("Content-Type: image/jpg");
     echo $imagick->getImageBlob();
 }
示例#8
0
 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"));
     //        $compositeModes = [
     //
     //            \Imagick::COMPOSITE_NO, \Imagick::COMPOSITE_ADD, \Imagick::COMPOSITE_ATOP, \Imagick::COMPOSITE_BLEND, \Imagick::COMPOSITE_BUMPMAP, \Imagick::COMPOSITE_CLEAR, \Imagick::COMPOSITE_COLORBURN, \Imagick::COMPOSITE_COLORDODGE, \Imagick::COMPOSITE_COLORIZE, \Imagick::COMPOSITE_COPYBLACK, \Imagick::COMPOSITE_COPYBLUE, \Imagick::COMPOSITE_COPY, \Imagick::COMPOSITE_COPYCYAN, \Imagick::COMPOSITE_COPYGREEN, \Imagick::COMPOSITE_COPYMAGENTA, \Imagick::COMPOSITE_COPYOPACITY, \Imagick::COMPOSITE_COPYRED, \Imagick::COMPOSITE_COPYYELLOW, \Imagick::COMPOSITE_DARKEN, \Imagick::COMPOSITE_DSTATOP, \Imagick::COMPOSITE_DST, \Imagick::COMPOSITE_DSTIN, \Imagick::COMPOSITE_DSTOUT, \Imagick::COMPOSITE_DSTOVER, \Imagick::COMPOSITE_DIFFERENCE, \Imagick::COMPOSITE_DISPLACE, \Imagick::COMPOSITE_DISSOLVE, \Imagick::COMPOSITE_EXCLUSION, \Imagick::COMPOSITE_HARDLIGHT, \Imagick::COMPOSITE_HUE, \Imagick::COMPOSITE_IN, \Imagick::COMPOSITE_LIGHTEN, \Imagick::COMPOSITE_LUMINIZE, \Imagick::COMPOSITE_MINUS, \Imagick::COMPOSITE_MODULATE, \Imagick::COMPOSITE_MULTIPLY, \Imagick::COMPOSITE_OUT, \Imagick::COMPOSITE_OVER, \Imagick::COMPOSITE_OVERLAY, \Imagick::COMPOSITE_PLUS, \Imagick::COMPOSITE_REPLACE, \Imagick::COMPOSITE_SATURATE, \Imagick::COMPOSITE_SCREEN, \Imagick::COMPOSITE_SOFTLIGHT, \Imagick::COMPOSITE_SRCATOP, \Imagick::COMPOSITE_SRC, \Imagick::COMPOSITE_SRCIN, \Imagick::COMPOSITE_SRCOUT, \Imagick::COMPOSITE_SRCOVER, \Imagick::COMPOSITE_SUBTRACT, \Imagick::COMPOSITE_THRESHOLD, \Imagick::COMPOSITE_XOR,
     //
     //        ];
     $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();
 }
 /**
  * function filter_render_type
  * Returns HTML markup containing an image with a data: URI
  * @param string $content The text to be rendered
  * @param string $font_file The path to a font file in a format ImageMagick can handle
  * @param integer $font_size The font size, in pixels (defaults to 28)
  * @param string $font_color The font color (defaults to 'black')
  * @param string $background_color The background color (defaults to 'transparent')
  * @param string $output_format The image format to use (defaults to 'png')
  * @return string HTML markup containing the rendered image
  **/
 public function filter_render_type($content, $font_file, $font_size, $font_color, $background_color, $output_format, $width)
 {
     // Preprocessing $content
     // 1. Strip HTML tags. It would be better to support them, but we just strip them for now.
     // 2. Decode HTML entities to UTF-8 charaaters.
     $content = html_entity_decode(strip_tags($content), ENT_QUOTES, 'UTF-8');
     // 3. Do word wrap when $width is specified. Not work for double-width characters.
     if (is_int($width)) {
         $content = wordwrap($content, floor($width / (0.3 * $font_size)));
     }
     $cache_group = strtolower(get_class($this));
     $cache_key = $font_file . $font_size . $font_color . $background_color . $output_format . $content . $width;
     if (!Cache::has(array($cache_group, md5($cache_key)))) {
         $font_color = new ImagickPixel($font_color);
         $background_color = new ImagickPixel($background_color);
         $draw = new ImagickDraw();
         $draw->setFont($font_file);
         $draw->setFontSize($font_size);
         $draw->setFillColor($font_color);
         $draw->setTextEncoding('UTF-8');
         $draw->annotation(0, $font_size * 2, $content);
         $canvas = new Imagick();
         $canvas->newImage(1000, $font_size * 5, $background_color);
         $canvas->setImageFormat($output_format);
         $canvas->drawImage($draw);
         // The following line ensures that the background color is set in the PNG
         // metadata, when using that format. This allows you, by specifying an RGBa
         // background color (e.g. #ffffff00) to create PNGs with a transparent background
         // for browsers that support it but with a "fallback" background color (the RGB
         // part of the RGBa color) for IE6, which does not support alpha in PNGs.
         $canvas->setImageBackgroundColor($background_color);
         $canvas->trimImage(0);
         Cache::set(array($cache_group, md5($cache_key)), $canvas->getImageBlob());
     }
     return '<img class="rendered-type" src="' . URL::get('display_rendertype', array('hash' => md5($cache_key), 'format' => $output_format)) . '" title="' . $content . '" alt="' . $content . '">';
 }
示例#10
0
 /**
  * 
  * 文字水印
  * @param unknown_type $data
  */
 public function addWaterText($data)
 {
     $draw = new ImagickDraw();
     $this->ImagickPixel = new ImagickPixel();
     $draw->clear();
     $draw->setfont($data['font']);
     $draw->setfontsize($data['size']);
     $this->ImagickPixel->setcolor($data['color']);
     $draw->setfillcolor($data['color']);
     $draw->setfillalpha($data['alpha']);
     $draw->settextalignment(imagick::GRAVITY_NORTHWEST);
     //左对齐
     $draw->annotation($data['pos_x'], $data['pos_y'], $data['literal']);
     $this->srcImg_source->drawimage($draw);
     $draw->destroy();
     return $this->srcImg_source;
 }
示例#11
0
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();
}
示例#12
0
 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->setTextUnderColor($color['bg']);
     $draw->setTextAntialias(true);
     $draw->setFillColor($color['text']);
     $draw->setFont(realpath('stuff/arialbd.ttf'));
     $code = $this->_user;
     $draw->setFontSize(strlen($code) > 8 ? 10 : 11);
     if (strlen($code) > 10) {
         $code = substr($code, 0, 9) . '...';
     }
     $draw->annotation(80, 13, $code);
     $textInfo = $this->_canvas->queryFontMetrics($draw, $code, null);
     $nextX = 80 + 9 + $textInfo['textWidth'];
     $draw->setFont(realpath('stuff/consola.ttf'));
     $draw->setFontSize(11);
     $draw->setFillColor($color['neutral']);
     $draw->annotation(5, 13, "хаброметр");
     $draw->setTextUnderColor($color['karma']);
     $draw->setFillColor($color['bg']);
     $draw->setFontSize(12);
     $draw->setFont(realpath('stuff/consolab.ttf'));
     $draw->annotation($nextX, 13, $text = sprintf('%01.2f', $this->_karma));
     $textInfo = $this->_canvas->queryFontMetrics($draw, $text, null);
     $nextX += $textInfo['textWidth'] + 4;
     $draw->setTextUnderColor($color['bg']);
     $draw->setFont(realpath('stuff/arialbd.ttf'));
     $text = sprintf('%01.2f', $this->_extremums['karma_min']) . '/' . sprintf('%01.2f', $this->_extremums['karma_max']);
     $draw->setFontSize(8);
     $draw->setFillColor($color['karma']);
     $draw->annotation($nextX, 13, $text);
     $textInfo = $this->_canvas->queryFontMetrics($draw, $text, null);
     $nextX += $textInfo['textWidth'] + 9;
     $draw->setFontSize(12);
     $draw->setFont(realpath('stuff/consolab.ttf'));
     $draw->setTextUnderColor($color['force']);
     $draw->setFillColor($color['bg']);
     $draw->annotation($nextX, 13, $text = sprintf('%01.2f', $this->_habraforce));
     $textInfo = $this->_canvas->queryFontMetrics($draw, $text, null);
     $nextX += $textInfo['textWidth'] + 4;
     $draw->setTextUnderColor($color['bg']);
     $draw->setFont(realpath('stuff/arialbd.ttf'));
     $text = sprintf('%01.2f', $this->_extremums['habraforce_min']) . '/' . sprintf('%01.2f', $this->_extremums['habraforce_max']);
     $draw->setFontSize(8);
     $draw->setFillColor($color['force']);
     $draw->annotation($nextX, 13, $text);
     $image = new Imagick('stuff/bg-user2.gif');
     $this->_canvas->compositeImage($image, Imagick::COMPOSITE_COPY, 64, 3, Imagick::CHANNEL_ALL);
     $image->clear();
     $image->destroy();
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     return true;
 }
示例#13
0
 /**
  * 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;
 }
示例#14
0
$filename = "temp/{$caveID}.png";
if (!file_exists($filename)) {
    define("NAME_LENGTH", 21);
    $config = new Config();
    $db = DbConnect();
    $cave = getCaveByID($caveID);
    if ($cave === 0) {
        exit(1);
    }
    $name = unhtmlentities($cave['name']);
    if (strlen($cave['name']) > NAME_LENGTH) {
        $cave['name'] = substr($cave['name'], 0, NAME_LENGTH - 2) . "..";
    }
    /* Create imagickdraw object */
    $draw = new ImagickDraw();
    /* Annotate some text */
    $draw->setFontSize(13);
    $draw->annotation(5, 20, "{$cave['name']}");
    $draw->setFontSize(10);
    $draw->annotation(5, 33, "({$cave['xCoord']}|{$cave['yCoord']})");
    /* Create a new imagick object */
    $im = new Imagick();
    /* Create new image. This will be used as fill pattern */
    $im->newImage(120, 40, new ImagickPixel('none'));
    $im->setImageFormat('png');
    /* Draw the ImagickDraw on to the canvas */
    $im->drawImage($draw);
    $im->rotateImage(new ImagickPixel('none'), -90);
    $im->writeImage($filename);
}
header("Location: {$filename}");
示例#15
0
 function __construct($chemin)
 {
     if (filter_var($chemin, FILTER_VALIDATE_URL)) {
         //URL
         $headers = @get_headers($chemin);
         if (strpos($headers[0], '404') != false) {
             //NOT FOUND
             //throw new \Exception("Not Found Image");
             $this->image = new \Imagick();
             $this->image->newImage(600, 600, new \ImagickPixel('white'));
             /* Création d'un nouvel objet imagick */
             $im = new \Imagick();
             /* Création d'une nouvelle image. Elle sera utilisée comme masque de remplissage */
             $im->newPseudoImage(50, 100, "gradient:gray-black");
             /* Création d'un nouvel objet imagickdraw */
             $draw = new \ImagickDraw();
             /* On commence un nouveau masque nommé "gradient" */
             $draw->pushPattern('gradient', 0, 0, 50, 110);
             /* Ajout du dégradé sur le masque */
             $draw->composite(\Imagick::COMPOSITE_OVER, 0, 0, 50, 110, $im);
             /* Fermeture du masque */
             $draw->popPattern();
             /* Utilisation du masque nommé "gradient" comme remplissage */
             $draw->setFillPatternURL('#gradient');
             /* Définition de la taille du texte à 52 */
             $draw->setFontSize(92);
             $draw->setFont(ROOT . DS . 'font/comic.ttf');
             /* Ajout d'un texte */
             $draw->annotation(20, 100, "Not Found !");
             $this->image->drawImage($draw);
         }
     } else {
         if (!file_exists($chemin)) {
             //throw new \Exception("Not Found Image");
             $this->image = new \Imagick();
             $this->image->newImage(600, 600, new \ImagickPixel('white'));
             /* Création d'un nouvel objet imagick */
             $im = new \Imagick();
             /* Création d'une nouvelle image. Elle sera utilisée comme masque de remplissage */
             $im->newPseudoImage(50, 100, "gradient:gray-black");
             /* Création d'un nouvel objet imagickdraw */
             $draw = new \ImagickDraw();
             /* On commence un nouveau masque nommé "gradient" */
             $draw->pushPattern('gradient', 0, 0, 50, 110);
             /* Ajout du dégradé sur le masque */
             $draw->composite(\Imagick::COMPOSITE_OVER, 0, 0, 50, 110, $im);
             /* Fermeture du masque */
             $draw->popPattern();
             /* Utilisation du masque nommé "gradient" comme remplissage */
             $draw->setFillPatternURL('#gradient');
             /* Définition de la taille du texte à 52 */
             $draw->setFontSize(92);
             $draw->setFont(ROOT . DS . 'font/comic.ttf');
             /* Ajout d'un texte */
             $draw->annotation(20, 100, "Not Found !");
             $this->image->drawImage($draw);
         }
     }
     $this->image = new \Imagick($chemin);
     $imageprops = $this->image->getImageGeometry();
     $this->width = $imageprops['width'];
     $this->height = $imageprops['height'];
     $this->image->setImageFormat("jpeg");
 }
示例#16
0
/**
 * Funció dibuixaEixos
 * Li pasem  per els parametres el array assignatures i el array de notes
 * Creem el grafic, el guardem i el mostrem
 */
function dibuixaEixos($array_assignatura, $array_notes)
{
    $colorAprobats = '#00cc00';
    //fillColorA
    $colorSuspesos = '#ff0000';
    //fillColorS
    $im = new Imagick();
    $im->newImage(1400, 500, 'White');
    $draw = new ImagickDraw();
    $draw->translate(25, 500 - 25);
    //$draw->setFillColor('none');
    $draw->setStrokeColor('Black');
    $draw->setStrokeWidth(1);
    $draw->setFont("fonts/Aaargh.ttf");
    $draw->setFontSize(12);
    /**
     * Dibuixa els eixos x i y
     *
     */
    $draw->line(0, 0, 50 * count($array_assignatura) + 15, 0);
    //eix x _
    $draw->line(0, 0, 0, -45 * 10);
    //eix y |
    /**
     * Dibuixa les linies del eix y
     *
     */
    $n = 0;
    for ($i = 0; $i <= 45 * 10; $i++) {
        if ($i % 45 == 0) {
            $draw->line(0, -$i, -5, -$i);
            $draw->annotation(-15, -$i, $n);
            $n++;
        }
    }
    $draw->setFontSize(13);
    $i = 15;
    $n = 0;
    foreach ($array_notes as $nota) {
        if ($GLOBALS['aprosus']) {
            if ($nota < 5) {
                $draw->setFillColor($colorSuspesos);
            } else {
                $draw->setFillColor($colorAprobats);
            }
        } else {
            $draw->setFillColor('#0000ff');
        }
        $draw->rectangle($i, 0, $i + 45, -$nota * 45);
        /* Escriu el text */
        $draw->annotation($i, 15, $array_assignatura[$n]);
        $n++;
        $i = $i + 45 + 15;
    }
    $im->drawImage($draw);
    $im->setImageFormat("png");
    //file_put_contents ("draw_polyline.png", $imagick);
    $im->writeImage('draw_grafic.jpg');
    //echo $num_assig." i ".$max_notes;
    echo "<img src='draw_grafic.jpg'/>";
}
示例#17
0
/**
 * handler for img requests
 */
function ProcessImgRequest()
{
    if ($_SERVER["REQUEST_METHOD"] == "GET") {
        $method = $_GET["method"];
        $params = explode(",", $_GET["params"]);
        $width = (int) $params[0];
        $height = (int) $params[1];
        if ($method == "placeholder") {
            $image = new Imagick();
            $image->newImage($width, $height, "#707070");
            $image->setImageFormat("png");
            $x = 0;
            $y = 0;
            $size = 40;
            $draw = new ImagickDraw();
            while ($y < $height) {
                $draw->setFillColor("#808080");
                $points = [["x" => $x, "y" => $y], ["x" => $x + $size, "y" => $y], ["x" => $x + $size * 2, "y" => $y + $size], ["x" => $x + $size * 2, "y" => $y + $size * 2]];
                $draw->polygon($points);
                $points = [["x" => $x, "y" => $y + $size], ["x" => $x + $size, "y" => $y + $size * 2], ["x" => $x, "y" => $y + $size * 2]];
                $draw->polygon($points);
                $x += $size * 2;
                if ($x > $width) {
                    $x = 0;
                    $y += $size * 2;
                }
            }
            $draw->setFillColor("#B0B0B0");
            $draw->setFontSize($width / 5);
            $draw->setFontWeight(800);
            $draw->setGravity(Imagick::GRAVITY_CENTER);
            $draw->annotation(0, 0, $width . " x " . $height);
            $image->drawImage($draw);
            header("Content-type: image/png");
            echo $image;
        } else {
            $file_name = $_GET["src"];
            $path_parts = pathinfo($file_name);
            switch ($path_parts["extension"]) {
                case "png":
                    $mime_type = "image/png";
                    break;
                case "gif":
                    $mime_type = "image/gif";
                    break;
                default:
                    $mime_type = "image/jpeg";
                    break;
            }
            $file_name = $path_parts["basename"];
            $image = ResizeImage($file_name, $method, $width, $height);
            header("Content-type: " . $mime_type);
            echo $image;
        }
    }
}
示例#18
0
$runningHt = 15;
for ($i = count($legends) - 1; $i >= 0; $i--) {
    $p = explode("\n", $titles[$i]);
    $draw = new ImagickDraw();
    $draw->setFont('Helvetica');
    $draw->setFontSize(12);
    $draw->annotation(5, $runningHt, $titles[$i]);
    $canvas->drawImage($draw);
    $canvas->compositeImage($legends[$i], imagick::COMPOSITE_OVER, 0, $runningHt + 12 * (count($p) - 1));
    $runningHt += $legends[$i]->getImageHeight() + 20 + 12 * (count($p) - 1);
}
$canvas->writeImage($tmp_dir . $id . '.legend.png');
// title
$canvas = new Imagick();
$canvas->newImage($w, 30, new ImagickPixel('white'));
$canvas->setImageFormat('png');
$draw = new ImagickDraw();
$draw->setFont('Helvetica');
$draw->setFontSize(18);
$draw->setGravity(imagick::GRAVITY_CENTER);
$draw->annotation(0, 0, $_REQUEST['title']);
$canvas->drawImage($draw);
$canvas->writeImage($tmp_dir . $id . '.title.png');
function mkLegendUrl($u)
{
    return preg_replace('/&(STYLES|SRS)[^&]+/', '', $u);
}
$handle = fopen($tmp_dir . $id . '.html', 'w');
fwrite($handle, "<html><head><title>" . $_REQUEST['title'] . "</title><style>td {vertical-align : top} img {border : 1px solid gray}</style></head><body><table><tr><td><img src='{$tmp_url}{$id}.title.png'></td></tr><tr><td><img src='{$tmp_url}{$id}.png'></td><td><img src='{$tmp_url}{$id}.legend.png'></td></tr></table></body></html>");
fclose($handle);
echo json_encode(array('html' => "{$tmp_url}{$id}.html", 'map' => "{$tmp_url}{$id}.png", 'legend' => "{$tmp_url}{$id}.legend.png"));
示例#19
0
         $draw->setFillColor("#808080");
         $points = [["x" => $x, "y" => $y], ["x" => $x + $size, "y" => $y], ["x" => $x + $size * 2, "y" => $y + $size], ["x" => $x + $size * 2, "y" => $y + $size * 2]];
         $draw->polygon($points);
         $points = [["x" => $x, "y" => $y + $size], ["x" => $x + $size, "y" => $y + $size * 2], ["x" => $x, "y" => $y + $size * 2]];
         $draw->polygon($points);
         $x += $size * 2;
         if ($x > $width) {
             $x = 0;
             $y += $size * 2;
         }
     }
     $draw->setFillColor("#B0B0B0");
     $draw->setFontSize($width / 5);
     $draw->setFontWeight(800);
     $draw->setGravity(Imagick::GRAVITY_CENTER);
     $draw->annotation(0, 0, $width . " x " . $height);
     $image->drawImage($draw);
     header("Content-type: image/png");
     echo $image;
 } else {
     $file_name = $_GET["src"];
     $path_parts = pathinfo($file_name);
     switch ($path_parts["extension"]) {
         case "png":
             $mime_type = "image/png";
             break;
         case "gif":
             $mime_type = "image/gif";
             break;
         default:
             $mime_type = "image/jpeg";
示例#20
0
文件: screen.php 项目: nicam/clarify
        $draw = new ImagickDraw();
        $draw->setFont('Nimbus-Sans-Bold');
        if ($reqwidth <= 300) {
            $draw->setFontSize(9);
            $radius = 5;
        } else {
            if ($reqwidth < 800) {
                $draw->setFontSize(12);
                $radius = 7;
                $offset = 1;
            } else {
                $draw->setFontSize(14);
                $radius = 10;
                $offset = 2;
            }
        }
        foreach ($comments as $comment) {
            $draw->setFillColor('black');
            $x = $comment['x'] * $factor;
            $y = $comment['y'] * $factor;
            $draw->circle($x + $radius, $y + $radius, $x + $radius * 2, $y + $radius * 2);
            $draw->setFillColor('white');
            $draw->setTextAlignment(2);
            $draw->annotation($x + $radius, $y + $radius + $radius / 2 + 1, $comment['nr']);
        }
        $image->drawImage($draw);
        // Output
        header('Content-Type: image/png');
        echo $image;
        break;
}
示例#21
0
 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)");
     // Prepare canvas for drawing main graph
     $draw = new ImagickDraw();
     $draw->setStrokeColor($color['line']);
     $draw->setFillColor($color['bg']);
     $draw->setStrokeAntialias(true);
     $draw->setStrokeWidth(2);
     // Prepare values for drawing main graph
     define('BOTTOM_PAD', 30);
     define('TOP_PAD', 25);
     define('LEFT_PAD', 43);
     define('RIGHT_PAD', 15);
     $graph = array('b' => self::HEIGHT - BOTTOM_PAD, 't' => TOP_PAD);
     $graph['height'] = $graph['b'] - $graph['t'];
     $dataHeight = $this->_max_karma - $this->_min_karma;
     if ($dataHeight != 0) {
         $graph['k'] = $graph['height'] / $dataHeight;
     } else {
         $graph['k'] = 1;
     }
     $karma = array_reverse($this->_karma);
     $graph['segmentWidth'] = (self::WIDTH - LEFT_PAD - RIGHT_PAD) / (count($karma) - 1);
     $lastX = LEFT_PAD;
     $lastY = $karma[0];
     $graph['cords'] = array();
     foreach ($karma as $y) {
         $graph['cords'][] = array('x' => (double) $lastX, 'y' => $graph['b'] - round($y - $this->_min_karma) * $graph['k']);
         $lastX += $graph['segmentWidth'];
     }
     //Draw graph
     $draw->polyline($graph['cords']);
     $this->_canvas->drawImage($draw);
     // Draw bottom bg
     define('TOP_SPACER', 10);
     $draw = new ImagickDraw();
     $draw->setFillColor($color['bottom_bg']);
     $draw->polygon(array(array('x' => 0, 'y' => $graph['b'] + TOP_SPACER), array('x' => self::WIDTH, 'y' => $graph['b'] + TOP_SPACER), array('x' => self::WIDTH, 'y' => self::HEIGHT), array('x' => 0, 'y' => self::HEIGHT)));
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     // Draw texts
     $draw = new ImagickDraw();
     $draw->setTextAntialias(true);
     $draw->setFontSize(12);
     $draw->setFillColor($color['text']);
     $draw->setFont(realpath('stuff/arial.ttf'));
     $draw->annotation(2, 13, 'Хаброметр юзера');
     $draw->setFont(realpath('stuff/arialbd.ttf'));
     $code = $this->_user;
     if (strlen($code) > 25) {
         $code = substr($code, 0, 22) . '...';
     }
     $draw->annotation(125, 13, $code);
     $image = new Imagick('stuff/bg-user2.gif');
     $this->_canvas->compositeImage($image, Imagick::COMPOSITE_COPY, 109, 2, Imagick::CHANNEL_ALL);
     $image->clear();
     $image->destroy();
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     $draw = new ImagickDraw();
     $draw->setFontSize(10);
     $draw->setFillColor($color['karma']);
     $draw->setFont(realpath('stuff/consola.ttf'));
     $draw->annotation(2, $graph['t'] + 5, sprintf('%01.2f', $this->_max_karma));
     $draw->annotation(2, $graph['b'] + 2, sprintf('%01.2f', $this->_min_karma));
     $draw->setFontSize(10);
     $draw->setFillColor($color['neutral']);
     $draw->setFont(realpath('stuff/consola.ttf'));
     $t = preg_split('/-|\\s|:/', $this->_logTime);
     $this->_canvas->annotateImage($draw, self::WIDTH - 3, $graph['b'] + 2, -90, $t[2] . '.' . $t[1] . '.' . substr($t[0], -2) . ' ' . $t[3] . ':' . $t[4]);
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     $draw = new ImagickDraw();
     $draw->setFillColor($color['karma']);
     $text = 'min/max: ' . sprintf('%01.2f', $this->_extremums['karma_min']) . ' / ' . sprintf('%01.2f', $this->_extremums['karma_max']);
     $draw->setFontSize(12);
     $draw->setFont(realpath('stuff/consola.ttf'));
     $draw->setFillColor($color['bg']);
     $draw->annotation(3, $graph['b'] + 25, $text);
     $draw->setFillColor($color['karma']);
     $draw->annotation(2, $graph['b'] + 24, $text);
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     $draw = new ImagickDraw();
     $draw->setTextAlignment(Imagick::ALIGN_RIGHT);
     $text = 'min/max: ' . sprintf('%01.2f', $this->_extremums['habraforce_min']) . ' / ' . sprintf('%01.2f', $this->_extremums['habraforce_max']);
     $draw->setFontSize(12);
     $draw->setFont(realpath('stuff/consola.ttf'));
     $draw->setFillColor($color['bg']);
     $draw->annotation(self::WIDTH - 3, $graph['b'] + 25, $text);
     $draw->setFillColor($color['force']);
     $draw->annotation(self::WIDTH - 2, $graph['b'] + 24, $text);
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     $draw = new ImagickDraw();
     $draw->setTextAlignment(Imagick::ALIGN_RIGHT);
     $draw->setTextUnderColor($color['karma']);
     $draw->setFillColor($color['bg']);
     $draw->setFontSize(14);
     $draw->setFont(realpath('stuff/consolab.ttf'));
     $textInfo = $this->_canvas->queryFontMetrics($draw, sprintf('%01.2f', $this->_habraforce), null);
     $draw->annotation($lastX - $graph['segmentWidth'] + 1 - $textInfo['textWidth'] - 10, 13, sprintf('%01.2f', $karma[count($karma) - 1]));
     $draw->setTextUnderColor($color['force']);
     $draw->setFillColor($color['bg']);
     $draw->annotation($lastX - $graph['segmentWidth'] + 1, 13, sprintf('%01.2f', $this->_habraforce));
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     $image = new Imagick('stuff/logo_mini.png');
     $this->_canvas->compositeImage($image, Imagick::COMPOSITE_COPY, 3, 47, Imagick::CHANNEL_ALL);
     $image->clear();
     $image->destroy();
     return true;
 }
示例#22
0
function setTextUnderColor($strokeColor, $fillColor, $backgroundColor, $textUnderColor)
{
    $draw = new \ImagickDraw();
    $draw->setStrokeColor($strokeColor);
    $draw->setFillColor($fillColor);
    $draw->setStrokeWidth(2);
    $draw->setFontSize(72);
    $draw->annotation(50, 75, "Lorem Ipsum!");
    $draw->setTextUnderColor($textUnderColor);
    $draw->annotation(50, 175, "Lorem Ipsum!");
    $imagick = new \Imagick();
    $imagick->newImage(500, 500, $backgroundColor);
    $imagick->setImageFormat("png");
    $imagick->drawImage($draw);
    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}
示例#23
0
 /**
  * Show image with error text.
  *
  * @param string $text
  * @param int $width
  * @param int $height
  */
 public static function showError($text, $width, $height)
 {
     $canvas = new Imagick();
     $canvas->newImage($width, $height, new ImagickPixel("white"));
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel("white"));
     $draw->setStrokeColor(new ImagickPixel("black"));
     $draw->polyline(array(array('x' => 0, 'y' => 0), array('x' => $width - 1, 'y' => 0), array('x' => $width - 1, 'y' => $height - 1), array('x' => 0, 'y' => $height - 1), array('x' => 0, 'y' => 0)));
     $canvas->drawImage($draw);
     $draw->destroy();
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel("black"));
     $draw->setFontSize(12);
     $draw->setTextAlignment(Imagick::ALIGN_CENTER);
     $draw->setTextAntialias(true);
     $draw->setFont(realpath('stuff/consolab.ttf'));
     $draw->annotation($width / 2, $height / 2, $text);
     $canvas->drawImage($draw);
     $canvas->setImageFormat('png');
     header("Content-Type: image/png");
     echo $canvas;
     $draw->destroy();
     $canvas->clear();
     $canvas->destroy();
     exit;
 }
示例#24
0
 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->setTextUnderColor($color['bg']);
     $draw->setTextAlignment(Imagick::ALIGN_CENTER);
     $draw->setTextAntialias(true);
     $draw->setFillColor($color['text']);
     $draw->setFont(realpath('stuff/arialbd.ttf'));
     $code = $this->_user;
     $draw->setFontSize(strlen($code) > 8 ? 10 : 11);
     if (strlen($code) > 10) {
         $code = substr($code, 0, 9) . '...';
     }
     $draw->annotation(self::WIDTH / 2, self::HEIGHT - 9, $code);
     $draw->setFont(realpath('stuff/consola.ttf'));
     $draw->setFontSize(11);
     $draw->setFillColor($color['neutral']);
     $draw->annotation(self::WIDTH / 2, 15, "хаброметр");
     $text = sprintf('%01.2f', $this->_extremums['karma_min']) . ' / ' . sprintf('%01.2f', $this->_extremums['karma_max']);
     $draw->setFontSize(9);
     $draw->setFillColor($color['karma']);
     $draw->annotation(self::WIDTH / 2, 55, $text);
     $text = sprintf('%01.2f', $this->_extremums['habraforce_min']) . ' / ' . sprintf('%01.2f', $this->_extremums['habraforce_max']);
     $draw->setFontSize(9);
     $draw->setFillColor($color['force']);
     $draw->annotation(self::WIDTH / 2, 95, $text);
     $draw->setTextUnderColor($color['karma']);
     $draw->setFillColor($color['bg']);
     $draw->setFontSize(14);
     $draw->setFont(realpath('stuff/consolab.ttf'));
     $draw->annotation(self::WIDTH / 2, 35, sprintf('%01.2f', $this->_karma));
     $draw->setTextUnderColor($color['force']);
     $draw->setFillColor($color['bg']);
     $draw->annotation(self::WIDTH / 2, 75, sprintf('%01.2f', $this->_habraforce));
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     return true;
 }
示例#25
0
 /**
  * Add text to the given ImagickDraw (just a tool function used by _buildImage)
  * @param ImagickDraw $draw         canvas to draw text
  * @param string      $color        text color
  * @param string      $font         font path
  * @param integer     $font_size    font size (in pixels)
  * @param integer     $x            text x pos
  * @param integer     $y            text y pos
  * @param string      $text         text
  * @access protected
  * @return void
  */
 protected function _addTextToDraw(&$draw, $color, $font, $font_size, $x, $y, $text)
 {
     $draw->setFillColor(new ImagickPixel($color));
     $draw->setFont($font);
     $draw->setFontSize($font_size);
     $draw->annotation($x, $y + $draw->getFontSize(), $text);
 }
 /**
  * @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);
 }
示例#27
0
function psychedelicFontGif($name = 'Danack')
{
    set_time_limit(3000);
    $aniGif = new \Imagick();
    $aniGif->setFormat("gif");
    $maxFrames = 11;
    $scale = 0.25;
    for ($frame = 0; $frame < $maxFrames; $frame++) {
        $draw = new \ImagickDraw();
        $draw->setStrokeOpacity(1);
        $draw->setFont("../fonts/CANDY.TTF");
        $draw->setfontsize(150 * $scale);
        for ($strokeWidth = 25; $strokeWidth > 0; $strokeWidth--) {
            $hue = intval(fmod($frame * 360 / $maxFrames + 170 + $strokeWidth * 360 / 25, 360));
            $color = "hsl({$hue}, 255, 128)";
            $draw->setStrokeColor($color);
            $draw->setFillColor($color);
            $draw->setStrokeWidth($strokeWidth * 3 * $scale);
            $draw->annotation(60 * $scale, 165 * $scale, $name);
        }
        $draw->setStrokeColor('none');
        $draw->setFillColor('black');
        $draw->setStrokeWidth(0);
        $draw->annotation(60 * $scale, 165 * $scale, $name);
        //Create an image object which the draw commands can be rendered into
        $imagick = new \Imagick();
        $imagick->newImage(650 * $scale, 230 * $scale, "#eee");
        $imagick->setImageFormat("png");
        //Render the draw commands in the ImagickDraw object
        //into the image.
        $imagick->drawImage($draw);
        $imagick->setImageDelay(5);
        $aniGif->addImage($imagick);
        $imagick->destroy();
    }
    $aniGif->setImageIterations(0);
    //loop forever
    $aniGif->deconstructImages();
    header("Content-Type: image/gif");
    echo $aniGif->getImagesBlob();
}
 /**
  * @see	\wcf\system\image\adapter\IImageAdapter::drawText()
  */
 public function drawText($text, $x, $y, $font, $size, $opacity = 1)
 {
     $draw = new \ImagickDraw();
     $draw->setFillOpacity($opacity);
     $draw->setFillColor($this->color);
     $draw->setTextAntialias(true);
     $draw->setFont($font);
     $draw->setFontSize($size);
     // draw text
     $draw->annotation($x, $y, $text);
     if ($this->imagick->getImageFormat() == 'GIF') {
         $this->imagick = $this->imagick->coalesceImages();
         do {
             $this->imagick->drawImage($draw);
         } while ($this->imagick->nextImage());
     } else {
         $this->imagick->drawImage($draw);
     }
 }
示例#29
0
 function renderImage()
 {
     /* Implement word wrapping... Ughhh... why is this NOT done for me!!!
            OK... I know the algorithm sucks at efficiency, but it's for short messages, okay?
        
            Make sure to set the font on the ImagickDraw Object first!
            @param image the Imagick Image Object
            @param draw the ImagickDraw Object
            @param text the text you want to wrap
            @param maxWidth the maximum width in pixels for your wrapped "virtual" text box
            @return an array of lines and line heights
        */
     function wordWrapAnnotation(\Imagick $imagick, $draw, $text, $maxWidth)
     {
         $words = explode(" ", $text);
         $lines = array();
         $i = 0;
         $lineHeight = 0;
         while ($i < count($words)) {
             $currentLine = $words[$i];
             if ($i + 1 >= count($words)) {
                 $lines[] = $currentLine;
                 break;
             }
             //Check to see if we can add another word to this line
             $metrics = $imagick->queryFontMetrics($draw, $currentLine . ' ' . $words[$i + 1]);
             while ($metrics['textWidth'] <= $maxWidth) {
                 //If so, do it and keep doing it!
                 $currentLine .= ' ' . $words[++$i];
                 if ($i + 1 >= count($words)) {
                     break;
                 }
                 $metrics = $imagick->queryFontMetrics($draw, $currentLine . ' ' . $words[$i + 1]);
             }
             //We can't add the next word to this line, so loop to the next line
             $lines[] = $currentLine;
             $i++;
             //Finally, update line height
             if ($metrics['textHeight'] > $lineHeight) {
                 $lineHeight = $metrics['textHeight'];
             }
         }
         return array($lines, $lineHeight);
     }
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     $lightColor = new \ImagickPixel('LightCoral');
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor($lightColor);
     $draw->setStrokeWidth(2);
     $draw->setFontSize(36);
     $draw->setFont("../fonts/Arial.ttf");
     $draw->annotation(50, 50, "Lorem Ipsum!");
     $msg = "Danack";
     $xpos = 0;
     $ypos = 0;
     list($lines, $lineHeight) = wordWrapAnnotation($imagick, $draw, $msg, 140);
     for ($i = 0; $i < count($lines); $i++) {
         $imagick->annotateImage($draw, $xpos, $ypos + $i * $lineHeight, 0, $lines[$i]);
     }
     header("Content-Type: image/jpg");
     echo $imagick->getImageBlob();
 }
示例#30
0
    $scaleRange[1] = $scaleRange[1] * 9 / 5 + 32;
    $u .= '&COLORBARONLY=true&width=' . $barSize[0] . '&height=' . $barSize[1];
    $img = '/tmp/' . time() . rand() . '.png';
    $c = file_get_contents($u);
    file_put_contents($img, $c);
    $origImg = new Imagick($img);
    $origImg->borderImage('black', 1, 1);
    $canvas = new Imagick();
    $canvas->newImage($barSize[0] + 75, $barSize[1] + 10, new ImagickPixel('transparent'));
    $canvas->setImageFormat('png');
    $canvas->compositeImage($origImg, imagick::COMPOSITE_OVER, 0, 10 / 2);
    $draw = new ImagickDraw();
    $draw->setFont('Helvetica');
    $draw->setFontSize(12);
    for ($i = 0; $i <= 1; $i += 0.25) {
        $draw->annotation($barSize[0] + 5, $barSize[1] * $i + 10, sprintf("%.02f F", ($scaleRange[1] - $scaleRange[0]) * (1 - $i) + $scaleRange[0]));
    }
    $canvas->drawImage($draw);
    $canvas->writeImage($img);
    header('Content-type: image/png');
    $c = file_get_contents($img);
    echo $c;
} else {
    $c = @file_get_contents(urldecode($u));
    $content_type = 'Content-Type: text/plain';
    for ($i = 0; $i < count($http_response_header); $i++) {
        if (preg_match('/content-type/i', $http_response_header[$i])) {
            $content_type = $http_response_header[$i];
        }
    }
    if ($c) {