File: 173_ImagickDraw_bezier_basic.phpt

package info (click to toggle)
php-imagick 3.4.4%2Bphp8.0%2B3.4.4-2%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,776 kB
  • sloc: ansic: 34,120; xml: 842; php: 188; pascal: 85; makefile: 2
file content (83 lines) | stat: -rw-r--r-- 2,283 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--TEST--
Test ImagickDraw, bezier
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php

$backgroundColor = 'rgb(225, 225, 225)';
$strokeColor = 'rgb(0, 0, 0)';
$fillColor = 'DodgerBlue2';

function bezier($strokeColor, $fillColor, $backgroundColor) {

    $draw = new \ImagickDraw();

    $strokeColor = new \ImagickPixel($strokeColor);
    $fillColor = new \ImagickPixel($fillColor);

    $draw->setStrokeOpacity(1);
    $draw->setStrokeColor($strokeColor);
    $draw->setFillColor($fillColor);

    $draw->setStrokeWidth(2);

    $smoothPointsSet = array(
        array(
            array('x' => 10.0 * 5, 'y' => 10.0 * 5),
            array('x' => 30.0 * 5, 'y' => 90.0 * 5),
            array('x' => 25.0 * 5, 'y' => 10.0 * 5),
            array('x' => 50.0 * 5, 'y' => 50.0 * 5),
        ),
        array(
            array('x' => 50.0 * 5, 'y' => 50.0 * 5),
            array('x' => 75.0 * 5, 'y' => 90.0 * 5),
            array('x' => 70.0 * 5, 'y' => 10.0 * 5),
            array('x' => 90.0 * 5, 'y' => 40.0 * 5),
        ),
    );

    foreach ($smoothPointsSet as $points) {
        $draw->bezier($points);
    }


    $disjointPoints = array(
        array(
            array('x' => 10 * 5, 'y' => 10 * 5),
            array('x' => 30 * 5, 'y' => 90 * 5),
            array('x' => 25 * 5, 'y' => 10 * 5),
            array('x' => 50 * 5, 'y' => 50 * 5),
        ),
        array(
            array('x' => 50 * 5, 'y' => 50 * 5),
            array('x' => 80 * 5, 'y' => 50 * 5),
            array('x' => 70 * 5, 'y' => 10 * 5),
            array('x' => 90 * 5, 'y' => 40 * 5),
        )
    );
    $draw->translate(0, 200);

    foreach ($disjointPoints as $points) {
        $draw->bezier($points);
    }

    //Create an image object which the draw commands can be rendered into
    $imagick = new \Imagick();
    $imagick->newImage(500, 500, $backgroundColor);
    $imagick->setImageFormat("png");

    //Render the draw commands in the ImagickDraw object 
    //into the image.
    $imagick->drawImage($draw);

    //Send the image to the browser
    $bytes = $imagick->getImageBlob();
    if (strlen($bytes) <= 0) { echo "Failed to generate image.";} 
}

bezier($strokeColor, $fillColor, $backgroundColor) ;
echo "Ok";
?>
--EXPECTF--
Ok