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;
 }
示例#2
0
 /**
  * Draws the triangle strip for the signature
  *
  * @param string $hexColour Hexadecimal colour value for the whole card
  */
 public function drawTriangleStrip($hexColour)
 {
     // The base for the triangles strip, to be drawn over the plain
     $darkTriangles = isset($_GET['darktriangles']);
     $backArea = new ImagickDraw();
     $backArea->setFillColor(new ImagickPixel($hexColour));
     $backArea->rectangle(self::SIG_MARGIN + self::SIG_STROKE_WIDTH, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, $this->baseWidth - self::SIG_STROKE_WIDTH + self::SIG_STROKE_WIDTH / 2 + 1, self::TRIANGLE_STRIP_HEIGHT - self::SIG_STROKE_WIDTH + self::SIG_ROUNDING * 4);
     $this->canvas->drawImage($backArea);
     $originalTriangles = new Imagick(self::IMG_TRIANGLES);
     $originalTriangles->cropImage($this->baseWidth, $this->baseHeight, $this->baseWidth / 2, $this->baseHeight / 2);
     $triangles = new Imagick();
     $triangles->newImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, new ImagickPixel($hexColour));
     $triangles = $triangles->textureImage($originalTriangles);
     // The gradient to draw over the triangles
     $trianglesGradient1 = new Imagick();
     $trianglesGradient1->newPseudoImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, 'gradient:' . 'none' . '-' . $hexColour);
     $trianglesGradient1->setImageOpacity(0.6);
     // The second gradient to draw over the triangles
     $trianglesGradient2 = new Imagick();
     $trianglesGradient2->newPseudoImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, 'gradient:' . '#4a4a4a' . '-' . '#313131');
     // Composite the black and white gradient onto the triangles
     $triangles->compositeImage($trianglesGradient2, Imagick::COMPOSITE_OVERLAY, 0, 0);
     $triangles->setImageOpacity($darkTriangles ? 0.2 : 0.1);
     // Composite the triangles onto the base
     $this->canvas->compositeImage($triangles, Imagick::COMPOSITE_DEFAULT, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, self::SIG_MARGIN + self::SIG_STROKE_WIDTH * 1.5);
     // Composite the triangles gradient onto the base
     $this->canvas->compositeImage($trianglesGradient1, Imagick::COMPOSITE_DEFAULT, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, self::SIG_MARGIN + self::SIG_STROKE_WIDTH * 1.5);
 }
示例#3
0
 /**
  * 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);
 }
示例#4
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();
 }
示例#5
0
 /**
  * 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;
 }
示例#6
0
 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);
 }
示例#7
0
function test_shape(&$canvas)
{
    $draw = new ImagickDraw();
    $draw->setFillColor('transparent');
    $draw->setStrokeColor('#F02B88');
    $draw->setStrokeWidth(9);
    $draw->translate(200, 100);
    $draw->rectangle(-50, -50, 50, 50);
    $draw->translate(200, 100);
    $draw->ellipse(0, 0, 100, 80, 0, 360);
    $draw->skewX(-30);
    $draw->translate(200, 100);
    $draw->circle(0, 0, 50, 50);
    $canvas->drawImage($draw);
}
示例#8
0
 /**
  * Draw rectangle to given image at certain position
  *
  * @param  Image   $image
  * @param  integer $x
  * @param  integer $y
  * @return boolean
  */
 public function applyToImage(Image $image, $x = 0, $y = 0)
 {
     $rectangle = new \ImagickDraw();
     // set background
     $bgcolor = new Color($this->background);
     $rectangle->setFillColor($bgcolor->getPixel());
     // set border
     if ($this->hasBorder()) {
         $border_color = new Color($this->border_color);
         $rectangle->setStrokeWidth($this->border_width);
         $rectangle->setStrokeColor($border_color->getPixel());
     }
     $rectangle->rectangle($this->x1, $this->y1, $this->x2, $this->y2);
     $image->getCore()->drawImage($rectangle);
     return true;
 }
示例#9
0
 /**
  * Draw a rectangle on the image.
  *
  * @param  int $x
  * @param  int $y
  * @param  int $w
  * @param  int $h
  * @return Imagick
  */
 public function rectangle($x, $y, $w, $h = null)
 {
     $x2 = $x + $w;
     $y2 = $y + (null === $h ? $w : $h);
     $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->rectangle($x, $y, $x2, $y2);
     $this->image->resource()->drawImage($draw);
     return $this;
 }
示例#10
0
 public function fill($x1, $y1, $x2, $y2, $color = array(0, 0, 0, 100))
 {
     is_string($color) and $color = $this->create_hex_color($color);
     if (is_array($color)) {
         if (\Arr::is_assoc($color)) {
             extract($color);
         } else {
             if (count($color) > 3) {
                 list($red, $green, $blue, $alpha) = $color;
             } else {
                 list($red, $green, $blue) = $color;
                 $alpha = 100;
             }
         }
         $alpha = round($alpha / 100, 1);
         $color = new \ImagickPixel('rgba(' . $red . ', ' . $green . ', ' . $blue . ', ' . str_replace(',', '.', $alpha) . ')');
     }
     $fill = new \ImagickDraw();
     $fill->setfillcolor($color);
     $fill->rectangle($x1, $y1, $x2, $y2);
     $this->imagick->drawimage($fill);
     return $this;
 }
示例#11
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();
 }
示例#12
0
 public function draw($image)
 {
     $draw = new \ImagickDraw();
     $draw->setStrokeWidth($this->borderSize);
     if (null !== $this->fillColor) {
         $fillColor = new \ImagickPixel($this->fillColor->getHexString());
         $draw->setFillColor($fillColor);
     } else {
         $draw->setFillOpacity(0);
     }
     if (null !== $this->borderColor) {
         $borderColor = new \ImagickPixel($this->borderColor->getHexString());
         $draw->setStrokeColor($borderColor);
     } else {
         $draw->setStrokeOpacity(0);
     }
     $x1 = $this->pos[0];
     $x2 = $x1 + $this->getWidth();
     $y1 = $this->pos[1];
     $y2 = $y1 + $this->getHeight();
     $draw->rectangle($x1, $y1, $x2, $y2);
     $image->getCore()->drawImage($draw);
     return $image;
 }
 private function colorizeWall()
 {
     $wall = new Imagick($this->wallImage);
     $im = new Imagick();
     $im->newimage(1280, 720, $this->baseColor, 'png');
     $wall->compositeimage($im, Imagick::COMPOSITE_MULTIPLY, 0, 0);
     $im->clear();
     // darken image
     if ($this->darkenValue < 100 && $this->darkenValue >= 50) {
         $wallAdjust = clone $wall;
         $wallAdjust->modulateimage($this->darkenValue, 100, 100);
         $wall->compositeimage($wallAdjust, Imagick::COMPOSITE_MULTIPLY, 0, 0);
         $wallAdjust->clear();
     }
     // lighten image
     if ($this->lightenValue > 0) {
         $wallAdjust = clone $wall;
         $draw = new ImagickDraw();
         $draw->setFillColor('#ffffff');
         $draw->setfillopacity($this->lightenValue / 100);
         $geometry = $wallAdjust->getImageGeometry();
         $width = $geometry['width'];
         $height = $geometry['height'];
         $draw->rectangle(0, 0, $width, $height);
         $wallAdjust->drawImage($draw);
         $wall->compositeimage($wallAdjust, Imagick::COMPOSITE_DEFAULT, 0, 0);
         $wallAdjust->clear();
     }
     // apply hue/saturation
     $wall->modulateimage(100, $this->saturationValue, $this->hueValue);
     $wall->compositeimage($this->mask, Imagick::COMPOSITE_DSTIN, 0, 0);
     return $wall;
 }
示例#14
0
 /**
  * Fills image with color or pattern
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $filling = $this->argument(0)->value();
     $x = $this->argument(1)->type('digit')->value();
     $y = $this->argument(2)->type('digit')->value();
     $imagick = $image->getCore();
     try {
         // set image filling
         $source = new Decoder();
         $filling = $source->init($filling);
     } catch (\Intervention\Image\Exception\NotReadableException $e) {
         // set solid color filling
         $filling = new Color($filling);
     }
     // flood fill if coordinates are set
     if (is_int($x) && is_int($y)) {
         // flood fill with texture
         if ($filling instanceof Image) {
             // create tile
             $tile = clone $image->getCore();
             // mask away color at position
             $tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false);
             // create canvas
             $canvas = clone $image->getCore();
             // fill canvas with texture
             $canvas = $canvas->textureImage($filling->getCore());
             // merge canvas and tile
             $canvas->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0);
             // replace image core
             $image->setCore($canvas);
             // flood fill with color
         } elseif ($filling instanceof Color) {
             // create canvas with filling
             $canvas = new \Imagick();
             $canvas->newImage($image->getWidth(), $image->getHeight(), $filling->getPixel(), 'png');
             // create tile to put on top
             $tile = clone $image->getCore();
             // mask away color at pos.
             $tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false);
             // save alpha channel of original image
             $alpha = clone $image->getCore();
             // merge original with canvas and tile
             $image->getCore()->compositeImage($canvas, \Imagick::COMPOSITE_DEFAULT, 0, 0);
             $image->getCore()->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0);
             // restore alpha channel of original image
             $image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
         }
     } else {
         if ($filling instanceof Image) {
             // fill whole image with texture
             $image->setCore($image->getCore()->textureImage($filling->getCore()));
         } elseif ($filling instanceof Color) {
             // fill whole image with color
             $draw = new \ImagickDraw();
             $draw->setFillColor($filling->getPixel());
             $draw->rectangle(0, 0, $image->getWidth(), $image->getHeight());
             $image->getCore()->drawImage($draw);
         }
     }
     return true;
 }
示例#15
0
function whirlyGif($numberDots, $numberFrames, $loopTime, $backgroundColor, $phaseMultiplier, $phaseDivider)
{
    $aniGif = new \Imagick();
    $aniGif->setFormat("gif");
    $width = 500;
    $height = $width;
    $numberDots = intval($numberDots);
    if ($numberDots < 1) {
        $numberDots = 1;
    }
    $maxFrames = $numberFrames;
    $frameDelay = ceil($loopTime / $maxFrames);
    $scale = 1;
    $startColor = new \ImagickPixel('red');
    $dots = [];
    for ($i = 0; $i < $numberDots; $i++) {
        $colorInfo = $startColor->getHSL();
        //Rotate the hue by 180 degrees
        $newHue = $colorInfo['hue'] + $i / $numberDots;
        if ($newHue > 1) {
            $newHue = $newHue - 1;
        }
        //Set the ImagickPixel to the new color
        $color = new \ImagickPixel('#ffffff');
        $colorInfo['saturation'] *= 0.95;
        $color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']);
        $dots[] = new Dot($color, $i, $numberDots, $width, $height);
    }
    for ($frame = 0; $frame < $maxFrames; $frame++) {
        $draw = new \ImagickDraw();
        $draw->setStrokeColor('none');
        $draw->setFillColor('none');
        $draw->rectangle(0, 0, $width, $height);
        $draw->translate($width / 2, $height / 2);
        foreach ($dots as $dot) {
            /** @var $dot Dot */
            $dot->render($draw, $frame, $maxFrames, $phaseMultiplier, $phaseDivider);
        }
        //Create an image object which the draw commands can be rendered into
        $imagick = new \Imagick();
        $imagick->newImage($width * $scale, $height * $scale, $backgroundColor);
        $imagick->setImageFormat("png");
        $imagick->setImageDispose(\Imagick::DISPOSE_PREVIOUS);
        //Render the draw commands in the ImagickDraw object
        //into the image.
        $imagick->drawImage($draw);
        $imagick->setImageDelay($frameDelay);
        $aniGif->addImage($imagick);
        $imagick->destroy();
    }
    $aniGif->setImageFormat('gif');
    $aniGif->setImageIterations(0);
    //loop forever
    $aniGif->mergeImageLayers(\Imagick::LAYERMETHOD_OPTIMIZEPLUS);
    header("Content-Type: image/gif");
    echo $aniGif->getImagesBlob();
}
示例#16
0
 /**
  * Draws a reactangle into the image.
  *
  * @param int $x1 Horizontal start.
  * @param int $y1 Vertical start.
  * @param int $x2 Horizontal end.
  * @param int $y2 Vertical end.
  */
 public function drawRectangle($x1, $y1, $x2, $y2)
 {
     $draw = new ImagickDraw();
     $draw->setFillColor('wheat');
     // Set up some colors to use for fill and outline
     $draw->setFillOpacity(0);
     $draw->setStrokeColor(new ImagickPixel('green'));
     $draw->rectangle($x1, $y1, $x2, $y2);
     // Draw the rectangle
     $this->Imgick->drawImage($draw);
 }
示例#17
0
$sql = $db->prepare("SELECT xCoord, yCoord, terrain\n                     FROM " . CAVE_TABLE . "\n                     ORDER BY yCoord, xCoord");
if (!$sql->execute()) {
    return die('Fehler beim erstellen des Bildes');
}
while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
    $map[$row['xCoord']][$row['yCoord']] = $GLOBALS['terrainList'][$row['terrain']]['color'];
}
$sql->closeCursor();
$squareWidth = $height / $mapSize['maxX'] - 1;
$squareHeight = $height / $mapSize['maxY'] - 1;
$draw = new ImagickDraw();
$i = $j = 0;
$coordWidth = $coordHeight = 1;
foreach ($map as $row) {
    $i++;
    foreach ($row as $col) {
        $j++;
        $draw->setFillColor("rgb(" . $col['r'] . "," . $col['g'] . "," . $col['b'] . ")");
        $draw->rectangle($coordWidth, $coordHeight, $coordWidth + $squareWidth, $coordHeight + $squareHeight);
        $coordHeight = $coordHeight + $squareHeight + 1;
    }
    $j = 0;
    $coordWidth = $coordWidth + $squareHeight + 1;
    $coordHeight = 1;
}
$image = new Imagick();
$image->newImage($width, $height, new ImagickPixel('none'));
$image->setImageFormat('png');
$image->drawImage($draw);
header('Content-type: image/png');
echo $image;
示例#18
0
 /**
  * Draw filled rectangle on current image
  *
  * @param string $color
  * @param int    $x
  * @param int    $y
  * @param int    $width
  * @param int    $height
  * @param float  $opacity
  *
  * @return image
  */
 public function fillRectangle($color, $x = 0, $y = 0, $width = null, $height = null, $opacity = 1)
 {
     $width = is_null($width) ? $this->width : $width;
     $height = is_null($height) ? $this->height : $height;
     $fill_rect = new \ImagickDraw();
     $fill_rect->setfillcolor(new \ImagickPixel($color));
     $fill_rect->setfillopacity($opacity);
     $fill_rect->rectangle($x, $y, $x + $width, $y + $height);
     $this->imagick->drawimage($fill_rect);
     return $this;
 }
示例#19
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'/>";
}
示例#20
0
function translate($strokeColor, $fillColor, $backgroundColor, $fillModifiedColor, $startX, $startY, $endX, $endY, $translateX, $translateY)
{
    $draw = new \ImagickDraw();
    $draw->setStrokeColor($strokeColor);
    $draw->setFillColor($fillColor);
    $draw->rectangle($startX, $startY, $endX, $endY);
    $draw->setFillColor($fillModifiedColor);
    $draw->translate($translateX, $translateY);
    $draw->rectangle($startX, $startY, $endX, $endY);
    $image = new \Imagick();
    $image->newImage(500, 500, $backgroundColor);
    $image->setImageFormat("png");
    $image->drawImage($draw);
    header("Content-Type: image/png");
    echo $image->getImageBlob();
}
 /**
  * Composites an Lenght-scale indicator
  *
  * @param object $imagickImage An Imagick object
  *
  * @return void
  */
 private function _addScaleBar($imagickImage)
 {
     $rect_width = 73;
     $rect_height = 56;
     // Calculate earth scale in piexls
     $earthInPixels = 2 * (6367.5 / 695500.0) * (959.705 / $this->roi->imageScale());
     $sizeInKM = round(50 * (2 * 6367.5) / $earthInPixels);
     $sizeInKMRounded = round($sizeInKM / 1000) * 1000;
     $scaleBarSizeInKM = number_format($sizeInKMRounded, 0, '.', ',') . ' km';
     // Convert x,y position of top left of EarthScale rectangle
     // from arcseconds to pixels
     if ($this->scaleX != 0 && $this->scaleY != 0) {
         $topLeftX = ($this->scaleX - $this->roi->left()) / $this->roi->imageScale();
         $topLeftY = (-$this->scaleY - $this->roi->top()) / $this->roi->imageScale();
     } else {
         $topLeftX = -1;
         $topLeftY = $imagickImage->getImageHeight() - $rect_height;
     }
     // Draw black rectangle background for indicator and label
     $draw = new ImagickDraw();
     $draw->setFillColor('#00000066');
     $draw->setStrokeColor('#888888FF');
     $draw->rectangle($topLeftX, $topLeftY, $topLeftX + $rect_width, $topLeftY + $rect_height);
     $imagickImage->drawImage($draw);
     // Draw Scalebar to scale
     $scalebar = new IMagick(HV_ROOT_DIR . '/resources/images/scalebar.png');
     $x = 1 + $topLeftX + $rect_width / 2 - 25;
     $y = 8 + $topLeftY + $rect_height / 2 + 4;
     $imagickImage->compositeImage($scalebar, IMagick::COMPOSITE_DISSOLVE, $x, $y);
     // Draw grey rectangle background for text label
     $draw = new ImagickDraw();
     $draw->setFillColor('#333333FF');
     $draw->rectangle($topLeftX + 1, $topLeftY + 1, $topLeftX + $rect_width - 1, $topLeftY + 16);
     $imagickImage->drawImage($draw);
     // Write 'Earth Scale' label in white
     $text = new IMagickDraw();
     $text->setTextEncoding('utf-8');
     $text->setFont(HV_ROOT_DIR . '/../resources/fonts/DejaVuSans.ttf');
     $text->setFontSize(10);
     $text->setFillColor('#ffff');
     $text->setTextAntialias(true);
     $text->setStrokeWidth(0);
     $x = $topLeftX + 15;
     $y = $topLeftY + 13;
     $imagickImage->annotateImage($text, $x, $y, 0, 'Bar Scale');
     // Write 'Scale in km' label in white
     $text2 = new IMagickDraw();
     $text2->setTextEncoding('utf-8');
     $text2->setFont(HV_ROOT_DIR . '/../resources/fonts/DejaVuSans.ttf');
     $text2->setFontSize(8);
     $text2->setFillColor('#ffff');
     $text2->setTextAntialias(true);
     $text2->setStrokeWidth(0);
     $text2->setTextAlignment(IMagick::ALIGN_CENTER);
     $x = $topLeftX + $rect_width / 2 + 2;
     $y = $topLeftY + 32;
     $imagickImage->annotateImage($text2, $x, $y, 0, $scaleBarSizeInKM);
     // Cleanup
     if (isset($draw)) {
         $draw->destroy();
     }
     if (isset($scalebar)) {
         $scalebar->destroy();
     }
     if (isset($text)) {
         $text->destroy();
     }
     if (isset($text2)) {
         $text2->destroy();
     }
 }
示例#22
0
 /**
  * Draw a 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 string $color    The line color of the rectangle.
  * @param string $fill     The color to fill the rectangle.
  */
 public function rectangle($x, $y, $width, $height, $color, $fill = 'none')
 {
     $draw = new ImagickDraw();
     $draw->setStrokeColor(new ImagickPixel($color));
     $draw->setFillColor(new ImagickPixel($fill));
     $draw->rectangle($x, $y, $x + $width, $y + $height);
     try {
         $res = $this->_imagick->drawImage($draw);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     $draw->destroy();
 }
示例#23
0
function blackBox(&$canvas, $o) {

	$rectangle = new Imagick();
	$rectangle->newPseudoImage($o['w'], $o['h'], "xc:none");
	$draw1 = new ImagickDraw();
	$draw1->pushPattern('gradient', 0, 0, 5, 5);
	$tile = new Imagick();
	$tile->readImage(realpath("assets/diag_tile.png"));
	$draw1->composite(Imagick::COMPOSITE_OVER, 0, 0, 5, 5, $tile);
	$draw1->popPattern();
	$draw1->setFillPatternURL('#gradient');
	$draw1->rectangle(0, 0, $o['w'], $o['h']);
	$rectangle->drawImage($draw1);

	$gradient = new Imagick();
	$gradient->newPseudoImage($o['w'], $o['h'], "gradient:#DDD-#666");

	$rectangle->compositeImage($gradient, Imagick::COMPOSITE_COPYOPACITY, 0, 0);

	$black = new Imagick();
	$black->newPseudoImage($o['w'], $o['h'], "xc:black");

	$layered = new Imagick();
	$layered->newPseudoImage($o['w'] + 20, $o['h'] + 20, "xc:none");
	$layered->compositeImage($black, Imagick::COMPOSITE_OVER, 5, 0);
	$layered->compositeImage($black, Imagick::COMPOSITE_OVER, 5, 5);
	$layered->compositeImage($gradient, Imagick::COMPOSITE_COPYOPACITY, 5, 5);
	$layered->blurImage(4, 5, imagick::CHANNEL_ALPHA);
	$layered->compositeImage($black, Imagick::COMPOSITE_DSTOUT, 0, 0);

	$canvas->compositeImage($layered, Imagick::COMPOSITE_OVER, $o['x'], $o['y']);
	$canvas->compositeImage($rectangle, Imagick::COMPOSITE_OVER, $o['x'], $o['y']);
}
 /**
  * @see	wcf\system\image\adapter\IImageAdapter::drawRectangle()
  */
 public function drawRectangle($startX, $startY, $endX, $endY)
 {
     $draw = new \ImagickDraw();
     $draw->setFillColor($this->color);
     $draw->setStrokeColor($this->color);
     $draw->rectangle($startX, $startY, $endX, $endY);
     $this->imagick->drawImage($draw);
 }
示例#25
0
function renderKernel(ImagickKernel $imagickKernel)
{
    $matrix = $imagickKernel->getMatrix();
    $imageMargin = 20;
    $tileSize = 20;
    $tileSpace = 4;
    $shadowSigma = 4;
    $shadowDropX = 20;
    $shadowDropY = 0;
    $radius = $tileSize / 2 * 0.9;
    $rows = count($matrix);
    $columns = count($matrix[0]);
    $imagickDraw = new \ImagickDraw();
    $imagickDraw->setFillColor('#afafaf');
    $imagickDraw->setStrokeColor('none');
    $imagickDraw->translate($imageMargin, $imageMargin);
    $imagickDraw->push();
    ksort($matrix);
    foreach ($matrix as $row) {
        ksort($row);
        $imagickDraw->push();
        foreach ($row as $cell) {
            if ($cell !== false) {
                $color = intval(255 * $cell);
                $colorString = sprintf("rgb(%f, %f, %f)", $color, $color, $color);
                $imagickDraw->setFillColor($colorString);
                $imagickDraw->rectangle(0, 0, $tileSize, $tileSize);
            }
            $imagickDraw->translate($tileSize + $tileSpace, 0);
        }
        $imagickDraw->pop();
        $imagickDraw->translate(0, $tileSize + $tileSpace);
    }
    $imagickDraw->pop();
    $width = $columns * $tileSize + ($columns - 1) * $tileSpace;
    $height = $rows * $tileSize + ($rows - 1) * $tileSpace;
    $imagickDraw->push();
    $imagickDraw->translate($width / 2, $height / 2);
    $imagickDraw->setFillColor('rgba(0, 0, 0, 0)');
    $imagickDraw->setStrokeColor('white');
    $imagickDraw->circle(0, 0, $radius - 1, 0);
    $imagickDraw->setStrokeColor('black');
    $imagickDraw->circle(0, 0, $radius, 0);
    $imagickDraw->pop();
    $canvasWidth = $width + 2 * $imageMargin;
    $canvasHeight = $height + 2 * $imageMargin;
    $kernel = new \Imagick();
    $kernel->newPseudoImage($canvasWidth, $canvasHeight, 'canvas:none');
    $kernel->setImageFormat('png');
    $kernel->drawImage($imagickDraw);
    /* create drop shadow on it's own layer */
    $canvas = $kernel->clone();
    $canvas->setImageBackgroundColor(new \ImagickPixel('rgb(0, 0, 0)'));
    $canvas->shadowImage(100, $shadowSigma, $shadowDropX, $shadowDropY);
    $canvas->setImagePage($canvasWidth, $canvasHeight, -5, -5);
    $canvas->cropImage($canvasWidth, $canvasHeight, 0, 0);
    /* composite original text_layer onto shadow_layer */
    $canvas->compositeImage($kernel, \Imagick::COMPOSITE_OVER, 0, 0);
    $canvas->setImageFormat('png');
    return $canvas;
}
示例#26
0
 /**
  * Fills the image at the specified locations. Designed specifically to
  * grey-out patient name, DoB, PID and HFA serial number,.
  *
  * @param Imagick $image
  */
 private function fillImage($image)
 {
     $draw = new ImagickDraw();
     //Create a new drawing class (?)
     $draw->setFillColor('grey');
     // main patient details - name, pid, dob:
     $draw->rectangle(190, 80, 2210, 254);
     // date, time, age:
     $draw->rectangle(1773, 291, 2160, 489);
     // bottom of image - serial number etc.:
     $draw->rectangle(190, 2960, 2160, 3099);
     $image->drawImage($draw);
     $image->setImageFormat('gif');
 }
 /**
  * Resizes image boundaries
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $width = $this->argument(0)->type('integer')->required()->value();
     $height = $this->argument(1)->type('integer')->required()->value();
     $anchor = $this->argument(2)->value('center');
     $relative = $this->argument(3)->type('boolean')->value();
     $bgcolor = $this->argument(4)->value();
     $original_width = $image->getWidth();
     $original_height = $image->getHeight();
     // check of only width or height is set
     $width = is_null($width) ? $original_width : intval($width);
     $height = is_null($height) ? $original_height : intval($height);
     // check on relative width/height
     if ($relative) {
         $width = $original_width + $width;
         $height = $original_height + $height;
     }
     // check for negative width/height
     $width = $width <= 0 ? $width + $original_width : $width;
     $height = $height <= 0 ? $height + $original_height : $height;
     // create new canvas
     $canvas = $image->getDriver()->newImage($width, $height, $bgcolor);
     // set copy position
     $canvas_size = $canvas->getSize()->align($anchor);
     $image_size = $image->getSize()->align($anchor);
     $canvas_pos = $image_size->relativePosition($canvas_size);
     $image_pos = $canvas_size->relativePosition($image_size);
     if ($width <= $original_width) {
         $dst_x = 0;
         $src_x = $canvas_pos->x;
         $src_w = $canvas_size->width;
     } else {
         $dst_x = $image_pos->x;
         $src_x = 0;
         $src_w = $original_width;
     }
     if ($height <= $original_height) {
         $dst_y = 0;
         $src_y = $canvas_pos->y;
         $src_h = $canvas_size->height;
     } else {
         $dst_y = $image_pos->y;
         $src_y = 0;
         $src_h = $original_height;
     }
     // make image area transparent to keep transparency
     // even if background-color is set
     $rect = new \ImagickDraw();
     $fill = $canvas->pickColor(0, 0, 'hex');
     $fill = $fill == '#ff0000' ? '#00ff00' : '#ff0000';
     $rect->setFillColor($fill);
     $rect->rectangle($dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1);
     $canvas->getCore()->drawImage($rect);
     $canvas->getCore()->transparentPaintImage($fill, 0, 0, false);
     // copy image into new canvas
     $image->getCore()->cropImage($src_w, $src_h, $src_x, $src_y);
     $canvas->getCore()->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, $dst_x, $dst_y);
     $canvas->getCore()->setImagePage(0, 0, 0, 0);
     // set new core to canvas
     $image->setCore($canvas->getCore());
     return true;
 }
 public function previewWithCropAction()
 {
     $previewWidth = 390;
     $previewHeight = 184;
     $fileRow = Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model')->getRow($this->_getParam('uploadId'));
     if (!$fileRow) {
         throw new Kwf_Exception("Can't find upload");
     }
     if ($fileRow->getHashKey() != $this->_getParam('hashKey')) {
         throw new Kwf_Exception_AccessDenied();
     }
     //Scale dimensions
     $dimensions = array($previewWidth, $previewHeight, 'cover' => false);
     $cache = Kwf_Assets_Cache::getInstance();
     $cacheId = 'previewLarge_' . $fileRow->id;
     if (!($output = $cache->load($cacheId))) {
         $output = array();
         $output['contents'] = Kwf_Media_Image::scale($fileRow->getFileSource(), $dimensions, $fileRow->id);
         $output['mimeType'] = $fileRow->mime_type;
         $cache->save($output, $cacheId);
     }
     $cropX = $this->_getParam('cropX');
     $cropY = $this->_getParam('cropY');
     $cropWidth = $this->_getParam('cropWidth');
     $cropHeight = $this->_getParam('cropHeight');
     $imageOriginal = new Imagick($fileRow->getFileSource());
     if ($this->_getParam('cropX') == null || $this->_getParam('cropY') == null || $this->_getParam('cropWidth') == null || $this->_getParam('cropHeight') == null) {
         //calculate default selection
         $dimension = $this->_getParam('dimension');
         if (!$dimension) {
             Kwf_Media_Output::output($output);
         }
         $dimension = array('width' => $this->_getParam('dimension_width') ? $this->_getParam('dimension_width') : 0, 'height' => $this->_getParam('dimension_height') ? $this->_getParam('dimension_height') : 0, 'cover' => $this->_getParam('dimension_cover') ? $this->_getParam('dimension_cover') : false);
         if ($dimension['width'] == Kwf_Form_Field_Image_UploadField::USER_SELECT) {
             $dimension['width'] = $this->_getParam('width');
         }
         if ($dimension['height'] == Kwf_Form_Field_Image_UploadField::USER_SELECT) {
             $dimension['height'] = $this->_getParam('height');
         }
         if (!$dimension['cover']) {
             Kwf_Media_Output::output($output);
         }
         if ($dimension['width'] == Kwf_Form_Field_Image_UploadField::CONTENT_WIDTH) {
             Kwf_Media_Output::output($output);
         }
         if ($dimension['height'] == 0 || $dimension['width'] == 0) {
             Kwf_Media_Output::output($output);
         }
         $cropX = 0;
         $cropY = 0;
         $cropHeight = $imageOriginal->getImageHeight();
         $cropWidth = $imageOriginal->getImageWidth();
         if ($imageOriginal->getImageHeight() / $dimension['height'] > $imageOriginal->getImageWidth() / $dimension['width']) {
             // orientate on width
             $cropHeight = $dimension['height'] * $imageOriginal->getImageWidth() / $dimension['width'];
             $cropY = ($imageOriginal->getImageHeight() - $cropHeight) / 2;
         } else {
             // orientate on height
             $cropWidth = $dimension['width'] * $imageOriginal->getImageHeight() / $dimension['height'];
             $cropX = ($imageOriginal->getImageWidth() - $cropWidth) / 2;
         }
     }
     // Calculate values relative to preview image
     $image = new Imagick();
     $image->readImageBlob($output['contents']);
     $previewFactor = 1;
     if ($image->getImageWidth() == $previewWidth) {
         $previewFactor = $image->getImageWidth() / $imageOriginal->getImageWidth();
     } else {
         if ($image->getImageHeight() == $previewHeight) {
             $previewFactor = $image->getImageHeight() / $imageOriginal->getImageHeight();
         }
     }
     $cropX = floor($cropX * $previewFactor);
     $cropY = floor($cropY * $previewFactor);
     $cropWidth = floor($cropWidth * $previewFactor);
     $cropHeight = floor($cropHeight * $previewFactor);
     $draw = new ImagickDraw();
     if ($this->_isLightImage($output)) {
         $draw->setFillColor('black');
     } else {
         $draw->setFillColor('white');
     }
     $draw->setFillOpacity(0.3);
     // if cropX == 0 or cropY == 0 no rectangle should be drawn, because it
     // can't be 0 wide on topmost and leftmost position so it will result in
     // a 1px line which is wrong
     //Top region
     if ($cropY > 0) {
         $draw->rectangle(0, 0, $image->getImageWidth(), $cropY);
     }
     //Left region
     if ($cropX > 0) {
         if ($cropY > 0) {
             $draw->rectangle(0, $cropY + 1, $cropX, $cropY + $cropHeight - 1);
         } else {
             $draw->rectangle(0, $cropY, $cropX, $cropY + $cropHeight - 1);
         }
     }
     //Right region
     if ($cropY > 0) {
         $draw->rectangle($cropX + $cropWidth, $cropY + 1, $image->getImageWidth(), $cropY + $cropHeight - 1);
     } else {
         $draw->rectangle($cropX + $cropWidth, $cropY, $image->getImageWidth(), $cropY + $cropHeight - 1);
     }
     //Bottom region
     $draw->rectangle(0, $cropY + $cropHeight, $image->getImageWidth(), $image->getImageHeight());
     $image->drawImage($draw);
     $output['contents'] = $image->getImageBlob();
     Kwf_Media_Output::output($output);
 }
示例#29
0
 /**
  * Color blend filter, more advanced version of colorize.
  *
  * Code by olav@redwall.ee on http://php.net/manual/en/imagick.colorizeimage.php
  *
  * @param $imageInstance
  * @param $color
  * @param int $alpha
  * @param int $composite_flag
  */
 private function _colorBlend($imagickInstance, $color, $alpha = 1, $composite_flag = \Imagick::COMPOSITE_COLORIZE)
 {
     $draw = new \ImagickDraw();
     $draw->setFillColor($color);
     $width = $imagickInstance->getImageWidth();
     $height = $imagickInstance->getImageHeight();
     $draw->rectangle(0, 0, $width, $height);
     $temporary = new \Imagick();
     $temporary->setBackgroundColor(new \ImagickPixel('transparent'));
     $temporary->newImage($width, $height, new \ImagickPixel('transparent'));
     $temporary->setImageFormat('png32');
     $temporary->drawImage($draw);
     $alphaChannel = clone $imagickInstance;
     $alphaChannel->setImageAlphaChannel(\Imagick::ALPHACHANNEL_EXTRACT);
     $alphaChannel->negateImage(false, \Imagick::CHANNEL_ALL);
     $imagickInstance->setImageClipMask($alphaChannel);
     $clone = clone $imagickInstance;
     $clone->compositeImage($temporary, $composite_flag, 0, 0);
     $clone->setImageOpacity($alpha);
     $imagickInstance->compositeImage($clone, \Imagick::COMPOSITE_DEFAULT, 0, 0);
 }
示例#30
0
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $draw = new ImagickDraw();
     $draw->setStrokeWidth($this->thickness);
     if (!is_null($this->color)) {
         $stroke = new ImagickPixel();
         $stroke->setColor($this->color);
         $draw->setStrokeColor($stroke);
     }
     if (!is_null($this->fill)) {
         $fill = new ImagickPixel();
         $fill->setColor($this->fill);
         $draw->setFillColor($fill);
     }
     $draw->rectangle($this->x1, $this->y1, $this->x2, $this->y2);
     $resource->drawImage($draw);
     return $image;
 }