function blueDiscAlpha($width, $height)
{
    $imagick = new Imagick();
    $imagick->newImage($width, $height, 'none');
    $draw = new ImagickDraw();
    $draw->setStrokeOpacity(0);
    $draw->setFillColor('blue');
    $draw->circle(2 * $width / 3, 2 * $height / 3, $width - ($width / 3 - $width / 4), 2 * $height / 3);
    $imagick->drawImage($draw);
    return $imagick;
}
예제 #2
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);
}
예제 #3
0
function makeSimpleGif($deconstruct)
{
    $aniGif = new \Imagick();
    $aniGif->setFormat("gif");
    $circleRadius = 20;
    $imageFrames = 40;
    $imageSize = 200;
    $background = new \Imagick();
    $background->newpseudoimage($imageSize, $imageSize, "plasma:tomato-steelblue");
    $blackWhite = new \Imagick();
    $blackWhite->newpseudoimage($imageSize, $imageSize, "gradient:black-white");
    $backgroundPalette = clone $background;
    $backgroundPalette->quantizeImage(240, \Imagick::COLORSPACE_RGB, 8, false, false);
    $blackWhitePalette = clone $blackWhite;
    $blackWhitePalette->quantizeImage(16, \Imagick::COLORSPACE_RGB, 8, false, false);
    $backgroundPalette->addimage($blackWhitePalette);
    for ($count = 0; $count < $imageFrames; $count++) {
        $drawing = new \ImagickDraw();
        $drawing->setFillColor('white');
        $drawing->setStrokeColor('rgba(64, 64, 64, 0.8)');
        $strokeWidth = 4;
        $drawing->setStrokeWidth($strokeWidth);
        $distanceToMove = $imageSize + ($circleRadius + $strokeWidth) * 2;
        $offset = $distanceToMove * $count / ($imageFrames - 1) - ($circleRadius + $strokeWidth);
        $drawing->translate($offset, $imageSize / 2 + $imageSize / 3 * cos(20 * $count / $imageFrames));
        $drawing->circle(0, 0, $circleRadius, 0);
        $frame = clone $background;
        $frame->drawimage($drawing);
        $frame->clutimage($backgroundPalette);
        $frame->setImageDelay(10);
        $aniGif->addImage($frame);
    }
    if ($deconstruct == true) {
        $aniGif = $aniGif->deconstructImages();
    }
    header("Content-Type: image/gif");
    echo $aniGif->getImagesBlob();
}
예제 #4
0
 function drawBezierChart($points, $roundness)
 {
     //Calculate the tangent vector for each point that you're drawing.
     $tangents = $this->getPointTangents($points);
     $positions = $this->getPointPositions($points);
     $numberOfPoints = count($points);
     $this->draw->setFillColor('#B42AAF9F');
     $this->draw->translate($this->chartWidth / 2, $this->chartHeight / 2);
     $this->draw->pathStart();
     $this->draw->pathMoveToAbsolute($positions[0][0], $positions[0][1]);
     //Scale that by the 'value' of each point aka the distance from the chart's centre.
     //Also scale it by how rounded you want the chart.
     for ($i = 0; $i < $numberOfPoints; $i++) {
         list($nextPositionX, $nextPositionY) = $positions[($i + 1) % $numberOfPoints];
         list($controlPoint1X, $controlPoint1Y) = $this->getControlPoint($points[$i], $positions[$i], $tangents[$i], 1, $roundness, count($points));
         list($controlPoint2X, $controlPoint2Y) = $this->getControlPoint($points[($i + 1) % $numberOfPoints], $positions[($i + 1) % $numberOfPoints], $tangents[($i + 1) % $numberOfPoints], -1, $roundness, count($points));
         $this->draw->pathCurveToAbsolute($controlPoint1X, $controlPoint1Y, $controlPoint2X, $controlPoint2Y, $nextPositionX, $nextPositionY);
     }
     $this->draw->pathClose();
     $this->draw->pathFinish();
     foreach ($this->points as $point) {
         $this->draw->circle($point[0], $point[1], $point[2], $point[3]);
     }
 }
예제 #5
0
 function getWhiteDisc()
 {
     $width = $this->width;
     $height = $this->height;
     $imagick = new \Imagick();
     $imagick->newImage($width, $height, 'black');
     $draw = new \ImagickDraw();
     $draw->setStrokeOpacity(0);
     $draw->setFillColor('white');
     $draw->circle($width / 2, $height / 2, $width / 4, $height / 2);
     $imagick->drawImage($draw);
     return $imagick;
 }
예제 #6
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;
}
예제 #7
0
 public function render(\ImagickDraw $draw, $frame, $maxFrames, $phaseMultiplier, $phaseDivider)
 {
     $innerDistance = 40;
     $outerDistance = 230;
     $sequenceFraction = $this->sequence / $this->numberDots;
     $angle = 2 * M_PI * $sequenceFraction;
     $trailSteps = 5;
     $trailLength = 0.1;
     $offsets = [100 => 0];
     for ($i = 0; $i <= $trailSteps; $i++) {
         $key = intval(50 * $i / $trailSteps);
         $offsets[$key] = $trailLength * ($trailSteps - $i) / $trailSteps;
     }
     //TODO - using a pattern would make the circles look more natural
     //$draw->setFillPatternURL();
     foreach ($offsets as $alpha => $offset) {
         $distanceFraction = $this->calculateFraction($frame, $maxFrames, $offset, $phaseMultiplier, $phaseDivider);
         $distance = lerp($distanceFraction, $innerDistance, $outerDistance);
         $xOffset = $distance * sin($angle);
         $yOffset = $distance * cos($angle);
         $draw->setFillColor($this->color);
         $draw->setFillAlpha($alpha / 100);
         $xOffset = $xOffset * $this->imageWidth / 500;
         $yOffset = $yOffset * $this->imageHeight / 500;
         $xSize = 4 * $this->imageWidth / 500;
         $ySize = 4 * $this->imageHeight / 500;
         $draw->circle($xOffset, $yOffset, $xOffset + $xSize, $yOffset + $ySize);
     }
 }
예제 #8
0
function opticrop($image, $w, $h, $out, $format)
{
    // source dimensions
    $imginfo = getimagesize($image);
    $w0 = $imginfo[0];
    $h0 = $imginfo[1];
    if ($w > $w0 || $h > $h0) {
        die("Target dimensions must be smaller or equal to source dimensions.");
    }
    // parameters for the edge-maximizing crop algorithm
    $r = 1;
    // radius of edge filter
    $nk = 9;
    // scale count: number of crop sizes to try
    $gamma = GAMMA;
    // edge normalization parameter -- see documentation
    $ar = $w / $h;
    // target aspect ratio (AR)
    $ar0 = $w0 / $h0;
    // target aspect ratio (AR)
    dprint(basename($image) . ": {$w0} x {$h0} => {$w} x {$h}");
    $img = new Imagick($image);
    $imgcp = clone $img;
    // compute center of edginess
    $img->edgeImage($r);
    $img->modulateImage(100, 0, 100);
    // grayscale
    $img->blackThresholdImage("#0f0f0f");
    $img->writeImage($out);
    // use gd for random pixel access
    $im = ImageCreateFromJpeg($out);
    $xcenter = 0;
    $ycenter = 0;
    $sum = 0;
    $n = 100000;
    for ($k = 0; $k < $n; $k++) {
        $i = mt_rand(0, $w0 - 1);
        $j = mt_rand(0, $h0 - 1);
        $val = imagecolorat($im, $i, $j) & 0xff;
        $sum += $val;
        $xcenter += ($i + 1) * $val;
        $ycenter += ($j + 1) * $val;
    }
    $xcenter /= $sum;
    $ycenter /= $sum;
    // crop source img to target AR
    if ($w0 / $h0 > $ar) {
        // source AR wider than target
        // crop width to target AR
        $wcrop0 = round($ar * $h0);
        $hcrop0 = $h0;
    } else {
        // crop height to target AR
        $wcrop0 = $w0;
        $hcrop0 = round($w0 / $ar);
    }
    // crop parameters for all scales and translations
    $params = array();
    // crop at different scales
    $hgap = $hcrop0 - $h;
    $hinc = $nk == 1 ? 0 : $hgap / ($nk - 1);
    $wgap = $wcrop0 - $w;
    $winc = $nk == 1 ? 0 : $wgap / ($nk - 1);
    // find window with highest normalized edginess
    $n = 10000;
    $maxbetanorm = 0;
    $maxfile = '';
    $maxparam = array('w' => 0, 'h' => 0, 'x' => 0, 'y' => 0);
    for ($k = 0; $k < $nk; $k++) {
        $hcrop = round($hcrop0 - $k * $hinc);
        $wcrop = round($wcrop0 - $k * $winc);
        $xcrop = $xcenter - $wcrop / 2;
        $ycrop = $ycenter - $hcrop / 2;
        dprint("crop: {$wcrop}, {$hcrop}, {$xcrop}, {$ycrop}");
        if ($xcrop < 0) {
            $xcrop = 0;
        }
        if ($xcrop + $wcrop > $w0) {
            $xcrop = $w0 - $wcrop;
        }
        if ($ycrop < 0) {
            $ycrop = 0;
        }
        if ($ycrop + $hcrop > $h0) {
            $ycrop = $h0 - $hcrop;
        }
        // debug
        $currfile = CACHE_PATH . "image{$k}.jpg";
        if (DEBUG > 0) {
            $currimg = clone $img;
            $c = new ImagickDraw();
            $c->setFillColor("red");
            $c->circle($xcenter, $ycenter, $xcenter, $ycenter + 4);
            $currimg->drawImage($c);
            $currimg->cropImage($wcrop, $hcrop, $xcrop, $ycrop);
            $currimg->writeImage($currfile);
            $currimg->destroy();
        }
        $beta = 0;
        for ($c = 0; $c < $n; $c++) {
            $i = mt_rand(0, $wcrop - 1);
            $j = mt_rand(0, $hcrop - 1);
            $beta += imagecolorat($im, $xcrop + $i, $ycrop + $j) & 0xff;
        }
        $area = $wcrop * $hcrop;
        $betanorm = $beta / ($n * pow($area, $gamma - 1));
        dprint("beta: {$beta}; betan: {$betanorm}");
        dprint("image{$k}.jpg:<br/>\n<img src=\"{$currfile}\"/>");
        // best image found, save it
        if ($betanorm > $maxbetanorm) {
            $maxbetanorm = $betanorm;
            $maxparam['w'] = $wcrop;
            $maxparam['h'] = $hcrop;
            $maxparam['x'] = $xcrop;
            $maxparam['y'] = $ycrop;
            $maxfile = $currfile;
        }
    }
    dprint("best image: {$maxfile}");
    if (FORMAT == 'json') {
        // return coordinates instead of image
        $data = json_encode($maxparam);
        file_put_contents($out, $data);
    } else {
        // return image
        $imgcp->cropImage($maxparam['w'], $maxparam['h'], $maxparam['x'], $maxparam['y']);
        $imgcp->scaleImage($w, $h);
        $imgcp->writeImage($out);
    }
    chmod($out, 0777);
    $img->destroy();
    $imgcp->destroy();
    return 0;
}
예제 #9
0
function setImageClipMask($imagePath)
{
    $imagick = new \Imagick();
    $imagick->readImage(realpath($imagePath));
    $width = $imagick->getImageWidth();
    $height = $imagick->getImageHeight();
    $clipMask = new \Imagick();
    $clipMask->newPseudoImage($width, $height, "canvas:transparent");
    $draw = new \ImagickDraw();
    $draw->setFillColor('white');
    $draw->circle($width / 2, $height / 2, $width / 2 + $width / 4, $height / 2);
    $clipMask->drawImage($draw);
    $imagick->setImageClipMask($clipMask);
    $imagick->negateImage(false);
    $imagick->setFormat("png");
    header("Content-Type: image/png");
    echo $imagick->getImagesBlob();
}
예제 #10
0
 /**
  * Draw a circle.
  *
  * @param integer $x     The x coordinate of the centre.
  * @param integer $y     The y coordinate of the centre.
  * @param integer $r     The radius of the circle.
  * @param string $color  The line color of the circle.
  * @param string $fill   The color to fill the circle.
  */
 public function circle($x, $y, $r, $color, $fill = 'none')
 {
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel($fill));
     $draw->setStrokeColor(new ImagickPixel($color));
     $draw->circle($x, $y, $r + $x, $y);
     try {
         $res = $this->_imagick->drawImage($draw);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     $draw->destroy();
 }
예제 #11
0
function setViewBox($strokeColor, $fillColor, $backgroundColor)
{
    $draw = new \ImagickDraw();
    $draw->setStrokeColor($strokeColor);
    $draw->setFillColor($fillColor);
    $draw->setStrokeWidth(2);
    $draw->setFontSize(72);
    /*
         
        Sets the overall canvas size to be recorded with the drawing vector data. Usually this will be specified using the same size as the canvas image. When the vector data is saved to SVG or MVG formats, the viewbox is use to specify the size of the canvas image that a viewer will render the vector data on.
    */
    $draw->circle(250, 250, 250, 0);
    $draw->setviewbox(0, 0, 200, 200);
    $draw->circle(125, 250, 250, 250);
    $draw->translate(250, 125);
    $draw->circle(0, 0, 125, 0);
    $imagick = new \Imagick();
    $imagick->newImage(500, 500, $backgroundColor);
    $imagick->setImageFormat("png");
    $imagick->drawImage($draw);
    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}
예제 #12
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;
}
예제 #13
0
 private function gs_displayCircles()
 {
     $this->img = new Imagick($this->imagePath);
     $draw = new \ImagickDraw();
     $strokeColor = new \ImagickPixel("rgb(210,0,0)");
     $fillColor = new \ImagickPixel("rgba(0,0,0,0)");
     $draw->setStrokeColor($strokeColor);
     $draw->setFillColor($fillColor);
     $draw->setStrokeWidth(1);
     for ($i = 0; $i < sizeof($this->data['extr']); $i++) {
         $p = $this->data['extr'][$i];
         $draw->circle($p['x'], $p['y'], $p['x'] + $p['sigma'] * 1.5, $p['y']);
     }
     $this->img->drawImage($draw);
 }