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); }
function drawChartBackground() { $this->draw->line(25, $this->chartHeight / 2, $this->chartWidth - 25, $this->chartHeight / 2); $this->draw->line($this->chartWidth / 2, 25, $this->chartWidth / 2, $this->chartHeight - 25); $this->draw->setFillColor('none'); $this->draw->circle($this->chartWidth / 2, $this->chartHeight / 2, $this->chartWidth / 2, $this->chartHeight / 2 + 200); $this->draw->circle($this->chartWidth / 2, $this->chartHeight / 2, $this->chartWidth / 2, $this->chartHeight / 2 + 100); }
/** * 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; }
/** * 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); }
/** * @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; }
/** * 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; }
/** * Draw a line on the image, returns the GD-handle * * @param Zend_Image_Adapter_ImageMagick image resource $handle Image to work on * @param Zend_Image_Action_DrawLine $lineObject The object containing all settings needed for drawing a line. * @return void */ public function perform(Zend_Image_Adapter_ImageMagick $adapter, Zend_Image_Action_DrawLine $lineObject) { $handle = $adapter->getHandle(); $draw = new ImagickDraw(); $draw->setStrokeWidth($lineObject->getStrokeWidth()); $color = $lineObject->getStrokeColor(); $draw->setStrokeColor((string) $color); $draw->setStrokeOpacity($lineObject->getStrokeAlpha()); $draw->line($lineObject->getPointStart()->getX(), $lineObject->getPointStart()->getY(), $lineObject->getPointEnd()->getX(), $lineObject->getPointEnd()->getY()); $handle->drawImage($draw); }
/** * @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; }
function GetView() { global $TMP_PATH; $tmp_file = ADEI::GetTmpFile(); $im = new Imagick(); $tmp = new Imagick(); $image = new Imagick(); $final = new Imagick(); $with_axes = new Imagick(); $output = new Imagick(); $tick = new ImagickDraw(); $ceiling = new ImagickDraw(); $color = new ImagickPixel('#666666'); $background = new ImagickPixel('none'); // Transparent date_default_timezone_set('UTC'); $servername = "localhost"; $username = "******"; $password = "******"; $dbname = "HDCP10"; $req = $this->req->CreateGroupRequest(); $req = $this->req->CreateDataRequest(); $fstart = $req->GetProp("view_pb_start", 0); $width = $req->GetProp("control_width", 800); $height = $req->GetProp("control_height", 600); $height = $height - 180; // 60px for the xaxis (50px) $start = 1367366400000000.0; // GMT: Wed, 01 May 2013 00:00:00 GMT $end = 1367452800000000.0; // GMT: Thu, 02 May 2013 00:00:00 GMT //$end = 1367539200000000; // GMT: Fri, 03 May 2013 00:00:00 GMT $current = $start; $step = 3600000000.0; try { $conn = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); while (true) { if ($current >= $end) { break; } $start_interval = $current; $end_interval = $start_interval + $step; $sql = "SELECT img_id, image, timestamp FROM Profiles_060_WTH_STATIC_EL90_Images_Stitch_Im1_3600 WHERE timestamp >= " . $start_interval . " AND timestamp < " . $end_interval; $stmt = $conn->query($sql); $row = $stmt->fetchObject(); if ($row == false) { $im->newImage($width, $height - $height * 20 / 100, "white"); } else { if (is_null($row->image)) { $im->newImage($width, $height - $height * 20 / 100, "white"); } else { $im->readimageblob($row->image); $im->resizeImage($width, $height - $height * 20 / 100, Imagick::FILTER_LANCZOS, 1); } } #$text = date('H:s', ($current / 1000000)); #$draw = new ImagickDraw(); $tick = new ImagickDraw(); $ceiling = new ImagickDraw(); /* Font properties */ #$draw->setFont('Arial'); #$draw->setFontSize(200); #$draw->setFillColor($color); #$draw->setStrokeAntialias(true); #$draw->setTextAntialias(true); /* Get font metrics */ #$metrics = $image->queryFontMetrics($draw, $text); /* Create text */ #$draw->annotation(0, $metrics['ascender']+20, $text); $tick->setStrokeWidth(10); $tick->setStrokeColor($color); $tick->setFillColor($color); $tick->line(0, 0, 0, 20); //imageline($image, $width/2, 0, $width/2, 50, $color); $ceiling->setStrokeColor($color); $ceiling->setFillColor($color); $ceiling->line(0, 0, $width, 0); /* Create image */ $image->newImage($width, 20, $background); $image->setImageFormat('png'); #$image->drawImage($draw); $image->drawImage($tick); $image->drawImage($ceiling); $im->addImage($image); $im->resetIterator(); $tmp = $im->appendImages(true); $final->addImage($tmp); $current = $end_interval; $im->clear(); $image->clear(); $tmp->clear(); $tick->clear(); $ceiling->clear(); } } catch (PDOException $e) { //echo "Connection failed: " . $e->getMessage(); } /* Append the images into one */ $final->resetIterator(); $combined = $final->appendImages(false); /* Output the image */ $combined->setImageFormat("png"); $combined->resizeImage($width, $height - $height * 20 / 100, Imagick::FILTER_LANCZOS, 1); $draw = new ImagickDraw(); /* Font properties */ $draw->setFont('Arial'); $draw->setFontSize(12); $draw->setFillColor($color); $draw->setStrokeAntialias(true); $draw->setTextAntialias(true); $runner = $start; $axis_interval = $width / 24; $i = 0; while ($runner < $end) { $text = date('H:s', $runner / 1000000); $metrics = $image->queryFontMetrics($draw, $text); $draw->annotation($i * $axis_interval, $metrics['ascender'] + 20, $text); $runner = $runner + $step; $i++; } $xaxis = new Imagick(); $xaxis->newImage($width, 50, $background); $xaxis->setImageFormat('png'); $xaxis->drawImage($draw); $with_axes->addImage($combined); $with_axes->addImage($xaxis); $with_axes->resetIterator(); $output = $with_axes->appendImages(true); file_put_contents("{$TMP_PATH}/{$tmp_file}", $output); return array("img" => array("id" => $tmp_file, "yaxis" => "testest"), "div" => array("class" => "image-player", "xml" => "<div id='media'>" . "<div style='width:100px; margin: 0 auto;'>1367539200000000</div>" . "<div id='jet' class='colormap'></div>" . "<div class='range'><p class='lower'>-2</p><p class='upper'>2</p></div>" . "<div style='clear: both;'></div>" . "<div id='media-controls'>" . "<button id='play-pause-button' title='play' onclick='togglePlayPause();'>Play</button>" . "<button id='stop-button' title='stop' onclick='stopPlay();'>Stop</button>" . "<progress id='progress-bar' min='0' max='100' value='0' style='width:" . ($width - $width * 10 / 100) . "px'>0% played</progress>" . "</div>" . "</div>" . "<div id='timestamp1' style='display: none;' data='" . $start . "'></div>" . "<div id='timestamp2' style='display: none;' data='0'></div>")); }
/** * 在图片上划线 * @param object $image Imagick的实例 * @param integer $num 画线的数量 * @return object Imagick的实例 */ protected function imagickLine($image, $num = 4) { $draw = new \ImagickDraw(); for ($i = 0; $i < $num; $i++) { $color = $this->randColor(); $startx = rand(0, $this->width); $endx = rand(0, $this->width); $starty = rand(0, $this->height); $endy = rand(0, $this->height); $draw->setStrokeColor($color); $draw->setFillColor($color); $draw->setStrokeWidth(2); $draw->line($startx, $starty, $endx, $endy); } $image->drawImage($draw); $draw->destroy(); return $image; }
/** * Method to add an arc to the image. * * @param int $x * @param int $y * @param int $start * @param int $end * @param int $w * @param int $h * @return \Pop\Image\Imagick */ public function drawArc($x, $y, $start, $end, $w, $h = null) { $wid = $w; $hgt = null === $h ? $w : $h; $draw = new \ImagickDraw(); $draw->setFillColor($this->setColor($this->fillColor)); $x1 = $w * cos($start / 180 * pi()); $y1 = $h * sin($start / 180 * pi()); $x2 = $w * cos($end / 180 * pi()); $y2 = $h * sin($end / 180 * pi()); $points = array(array('x' => $x, 'y' => $y), array('x' => $x + $x1, 'y' => $y + $y1), array('x' => $x + $x2, 'y' => $y + $y2)); $draw->polygon($points); $draw->ellipse($x, $y, $wid, $hgt, $start, $end); $this->resource->drawImage($draw); if (null !== $this->strokeWidth) { $draw = new \ImagickDraw(); $draw->setFillColor($this->setColor($this->fillColor)); $draw->setStrokeColor($this->setColor($this->strokeColor)); $draw->setStrokeWidth(null === $this->strokeWidth ? 1 : $this->strokeWidth); $draw->ellipse($x, $y, $wid, $hgt, $start, $end); $draw->line($x, $y, $x + $x1, $y + $y1); $draw->line($x, $y, $x + $x2, $y + $y2); $this->resource->drawImage($draw); } return $this; }
if (is_null($row->image)) { $im->newImage($width, $height, "white"); } else { $im->readimageblob($row->image); $im->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1); } } $tick = new ImagickDraw(); $tick->setStrokeWidth(10); $tick->setStrokeColor($color); $tick->setFillColor($color); $tick->line(0, 0, 0, 20); $ceiling = new ImagickDraw(); $ceiling->setStrokeColor($color); $ceiling->setFillColor($color); $ceiling->line(0, 0, $width, 0); /* Create image */ $image->newImage($width, 20, $background); $image->setImageFormat('png'); $image->drawImage($tick); $image->drawImage($ceiling); $im->addImage($image); $im->resetIterator(); $tmp = $im->appendImages(true); $final->addImage($tmp); $current = $end_interval; $im->clear(); $image->clear(); $tmp->clear(); $tick->clear(); $ceiling->clear();
/** * Draw a pie slice on the image. * * @param int $x * @param int $y * @param int $start * @param int $end * @param int $w * @param int $h * @return Imagick */ public function pie($x, $y, $start, $end, $w, $h = null) { $wid = $w; $hgt = null === $h ? $w : $h; $draw = new \ImagickDraw(); $draw->setFillColor($this->image->getColor($this->fillColor)); $x1 = $w * cos($start / 180 * pi()); $y1 = $h * sin($start / 180 * pi()); $x2 = $w * cos($end / 180 * pi()); $y2 = $h * sin($end / 180 * pi()); $points = [['x' => $x, 'y' => $y], ['x' => $x + $x1, 'y' => $y + $y1], ['x' => $x + $x2, 'y' => $y + $y2]]; $draw->polygon($points); $draw->ellipse($x, $y, $wid, $hgt, $start, $end); $this->image->resource()->drawImage($draw); if ($this->strokeWidth > 0) { $draw = new \ImagickDraw(); $draw->setFillColor($this->image->getColor($this->fillColor)); $draw->setStrokeColor($this->image->getColor($this->strokeColor)); $draw->setStrokeWidth($this->strokeWidth); $draw->ellipse($x, $y, $wid, $hgt, $start, $end); $draw->line($x, $y, $x + $x1, $y + $y1); $draw->line($x, $y, $x + $x2, $y + $y2); $this->image->resource()->drawImage($draw); } return $this; }
/** * Horizontal line insertion */ protected function WriteLine() { if ($this->useImageMagick) { $x1 = $this->width * $this->scale * 0.15; $x2 = $this->textFinalX; $y1 = rand($this->height * $this->scale * 0.4, $this->height * $this->scale * 0.65); $y2 = rand($this->height * $this->scale * 0.4, $this->height * $this->scale * 0.65); $width = $this->lineWidth / 2 * $this->scale; $draw = new ImagickDraw(); $draw->setFillColor($this->GdFgColor); for ($i = $width * -1; $i <= $width; $i++) { $draw->line($x1, $y1 + $i, $x2, $y2 + $i); } $this->im->drawImage($draw); } else { $x1 = $this->width * $this->scale * 0.15; $x2 = $this->textFinalX; $y1 = rand($this->height * $this->scale * 0.4, $this->height * $this->scale * 0.65); $y2 = rand($this->height * $this->scale * 0.4, $this->height * $this->scale * 0.65); $width = $this->lineWidth / 2 * $this->scale; for ($i = $width * -1; $i <= $width; $i++) { imageline($this->im, $x1, $y1 + $i, $x2, $y2 + $i, $this->GdFgColor); } } }
$i++; } $xaxis = new Imagick(); $xaxis->newImage($width, 50, $background); $xaxis->setImageFormat('png'); $xaxis->drawImage($draw); $yaxis_top = new Imagick(); $yaxis_top->newImage($width_yaxis, $height - 68, $background); $yaxis_top->setImageFormat('png'); $ytick = new ImagickDraw(); $ytick->setStrokeWidth(1); $ytick->setStrokeColor($color); $ytick->setFillColor($color); $ybox = ($height - 68) / 8; for ($i = 0; $i <= 8; $i++) { $ytick->line($width_yaxis * 0.8, $i * $ybox, $width_yaxis, $i * $ybox); $yaxis_top->annotateImage($draw, 10, $height - 68 - $i * $ybox - 5, 0, $i * 1000); } $yaxis_top->drawImage($ytick); $yaxis_bot = new Imagick(); $yaxis_bot->newImage($width_yaxis, 68, $background); $yaxis_bot->setImageFormat('png'); $yaxis->addImage($yaxis_top); $yaxis->addImage($yaxis_bot); $yaxis->resetIterator(); $yaxis_output = $yaxis->appendImages(true); $with_axes->addImage($combined); $with_axes->addImage($xaxis); $with_axes->resetIterator(); $output = $with_axes->appendImages(true); $path_parts = pathinfo($tmp_file);
function setTextAlignment($strokeColor, $fillColor, $backgroundColor) { $draw = new \ImagickDraw(); $draw->setStrokeColor($strokeColor); $draw->setFillColor($fillColor); $draw->setStrokeWidth(1); $draw->setFontSize(36); $draw->setTextAlignment(\Imagick::ALIGN_LEFT); $draw->annotation(250, 75, "Lorem Ipsum!"); $draw->setTextAlignment(\Imagick::ALIGN_CENTER); $draw->annotation(250, 150, "Lorem Ipsum!"); $draw->setTextAlignment(\Imagick::ALIGN_RIGHT); $draw->annotation(250, 225, "Lorem Ipsum!"); $draw->line(250, 0, 250, 500); $imagick = new \Imagick(); $imagick->newImage(500, 500, $backgroundColor); $imagick->setImageFormat("png"); $imagick->drawImage($draw); header("Content-Type: image/png"); echo $imagick->getImageBlob(); }
$canvas->compositeImage($scaleLineTop, imagick::COMPOSITE_OVER, $w - ($scaleLineWidth + 15) - $compassImg->getImageWidth(), $h - ($scaleLineHeight * 2 + 15)); // bottom $scaleLineBottom = new Imagick(); $scaleLineBottom->newImage($scaleLineBottomWidth, $scaleLineHeight, new ImagickPixel('white')); $scaleLineBottom->setImageFormat('png'); $draw = new ImagickDraw(); $draw->setFont('Helvetica'); $draw->setFontSize(12); $draw->setGravity(imagick::GRAVITY_CENTER); $draw->annotation(0, 0, $json->{'scaleLineBottom'}->{'val'}); $scaleLineBottom->drawImage($draw); $scaleLineBottom->borderImage('black', $lineWidth, $lineWidth); $draw = new ImagickDraw(); $draw->setStrokeColor(new ImagickPixel('white')); $draw->setStrokeWidth($lineWidth * 2); $draw->line(0, $scaleLineHeight + 2, $scaleLineBottomWidth + $lineWidth * 2, $scaleLineHeight + 2); $scaleLineBottom->drawImage($draw); $canvas->compositeImage($scaleLineBottom, imagick::COMPOSITE_OVER, $w - ($scaleLineWidth + 15) - $compassImg->getImageWidth(), $h - ($scaleLineHeight + 15 - $lineWidth)); $canvas->writeImage($tmp_dir . $id . '.png'); $canvas = new Imagick(); $canvas->newImage($legSize[0], $legSize[1], new ImagickPixel('white')); $canvas->setImageFormat('png'); $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));
/** * Draw a dashed line. * * @param integer $x0 The x co-ordinate of the start. * @param integer $y0 The y co-ordinate of the start. * @param integer $x1 The x co-ordinate of the end. * @param integer $y1 The y co-ordinate of the end. * @param string $color The line color. * @param string $width The width of the line. * @param integer $dash_length The length of a dash on the dashed line * @param integer $dash_space The length of a space in the dashed line */ public function dashedLine($x0, $y0, $x1, $y1, $color = 'black', $width = 1, $dash_length = 2, $dash_space = 2) { $draw = new ImagickDraw(); $draw->setStrokeColor(new ImagickPixel($color)); $draw->setStrokeWidth($width); $draw->setStrokeDashArray(array($dash_length, $dash_space)); $draw->line($x0, $y0, $x1, $y1); try { $res = $this->_imagick->drawImage($draw); } catch (ImageException $e) { throw new Horde_Image_Exception($e); } $draw->destroy(); }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $draw = new ImagickDraw(); $draw->setFillColor($this->getColor()); $draw->line($this->getStartX(), $this->getStartY(), $this->getEndX(), $this->getEndY()); $resource->drawImage($draw); return $image; }
function GetView() { global $TMP_PATH; $tmp_file = ADEI::GetTmpFile(); $servername = "localhost"; $username = "******"; $password = "******"; $dbname = "HDCP10"; $width = 800; $height = 600; $window = "1365832800-1365854400"; $interval = explode("-", $this->window); $total_seconds = $interval[1] - $interval[0]; $start = $interval[0] * 1000000; $end = $interval[1] * 1000000; $im = new Imagick(); $draw2 = new ImagickDraw(); $draw2->setStrokeColor("#808080"); $draw2->setStrokeWidth(1); $draw2->setFontSize(72); $draw2->line(700, 240, 800, 240); $ystroke = new Imagick(); $ystroke->newImage(800, 480, "white"); $ystroke->setImageFormat("png"); $ystroke->drawImage($draw2); $im->addImage($ystroke); $draw = new ImagickDraw(); $draw->setStrokeColor("#808080"); $draw->setStrokeWidth(100); $draw->setFontSize(72); $draw->line(100, 0, 100, 480); $yaxis = new Imagick(); $yaxis->newImage(100, 480, "white"); $yaxis->setImageFormat("png"); $yaxis->drawImage($draw); $im->addImage($yaxis); try { $conn = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT count(*) FROM Profiles_060_WTH_STATIC_EL90_Images_1 WHERE P_id = 8"; $stmt = $conn->query($sql); $row = $stmt->fetch(); $total = $row[0]; $sql = "SELECT img_id, image FROM Profiles_060_WTH_STATIC_EL90_Images_1 WHERE P_id = 8 ORDER BY img_id ASC"; $stmt = $conn->query($sql); while ($row = $stmt->fetchObject()) { if (is_null($row->image)) { $im->newImage(7, 480, "white"); continue; } $im->readimageblob($row->image); } } catch (PDOException $e) { //echo "Connection failed: " . $e->getMessage(); } /* Create new imagick object */ //$im = new Imagick(); /* create red, green and blue images */ //$im->newImage(100, 50, "red"); //$im->newImage(100, 50, "green"); //$im->newImage(100, 50, "blue"); /* Append the images into one */ $im->resetIterator(); $combined = $im->appendImages(false); /* Output the image */ $combined->setImageFormat("png"); /* Having to do alot of resizing, i needed to know the speeds of the different resize filters. This was how long it took to resize a 5906x5906 JPEG image to 1181x1181. FILTER_POINT took: 0.334532976151 seconds FILTER_BOX took: 0.777871131897 seconds FILTER_TRIANGLE took: 1.3695909977 seconds FILTER_HERMITE took: 1.35866093636 seconds FILTER_HANNING took: 4.88722896576 seconds FILTER_HAMMING took: 4.88665103912 seconds FILTER_BLACKMAN took: 4.89026689529 seconds FILTER_GAUSSIAN took: 1.93553304672 seconds FILTER_QUADRATIC took: 1.93322920799 seconds FILTER_CUBIC took: 2.58396601677 seconds FILTER_CATROM took: 2.58508896828 seconds FILTER_MITCHELL took: 2.58368492126 seconds FILTER_LANCZOS took: 3.74232912064 seconds FILTER_BESSEL took: 4.03305602074 seconds FILTER_SINC took: 4.90098690987 seconds */ $combined->resizeImage(1200, 600, Imagick::FILTER_LANCZOS, 1); #$draw3 = new ImagickDraw(); #$draw3->setStrokeColor("black"); //$draw3->setFillColor($fillColor); #$draw3->setStrokeWidth(0.1); #$draw3->setFontSize(8); #$combined->annotateImage($draw3, 0, 300, 0, "500"); file_put_contents("{$TMP_PATH}/{$tmp_file}", $combined); return array("img" => array("id" => $tmp_file)); }
/** * 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'/>"; }
/** * {@inheritdoc} */ public function line(PointInterface $start, PointInterface $end, ColorInterface $color, $thickness = 1) { try { $pixel = $this->getColor($color); $line = new \ImagickDraw(); $line->setStrokeColor($pixel); $line->setStrokeWidth(max(1, (int) $thickness)); $line->setFillColor($pixel); $line->line($start->getX(), $start->getY(), $end->getX(), $end->getY()); $this->imagick->drawImage($line); $pixel->clear(); $pixel->destroy(); $line->clear(); $line->destroy(); } catch (\ImagickException $e) { throw new RuntimeException('Draw line operation failed', $e->getCode(), $e); } return $this; }
fclose($handle); $img = new Imagick($tmp_dir . $id . '.bm.png'); $canvas->compositeImage($img, imagick::COMPOSITE_OVER, $basemap[$k]['x'], $basemap[$k]['y']); } $canvas->compositeImage($olay, imagick::COMPOSITE_OVER, 0, 0); foreach ($tracks as $k => $v) { for ($i = 0; $i < count($tracks[$k]); $i++) { $draw = new ImagickDraw(); $draw->setStrokeColor(new ImagickPixel($tracks[$k][$i]['color'])); if ($tracks[$k][$i]['stroke'] == 'dot') { $draw->setStrokeDashArray(array(2, 3)); } else { $draw->setStrokeWidth(2); } for ($j = 1; $j < count($tracks[$k][$i]['data']); $j++) { $draw->line($tracks[$k][$i]['data'][$j - 1][0], $tracks[$k][$i]['data'][$j - 1][1], $tracks[$k][$i]['data'][$j][0], $tracks[$k][$i]['data'][$j][1]); } $canvas->drawImage($draw); } } foreach ($features as $k => $v) { $img = new Imagick($iconSysPath . $k . '.png'); for ($i = 0; $i < count($features[$k]); $i++) { $cloneImg = $img->clone(); // don't rotate for now // $cloneImg->rotateImage(new ImagickPixel('none'),$features[$k][$i][2]); $dim = $cloneImg->getImageGeometry(); $canvas->compositeImage($cloneImg, imagick::COMPOSITE_OVER, $features[$k][$i][0] - $dim['width'] / 2, $features[$k][$i][1] - $dim['height'] / 2); } } $canvas->writeImage($tmp_dir . $id . '.print.png');