xref: /imagick/examples/polygon.php (revision 41856e90)
1<?php
2/*
3	This examples was ported from ImageMagick C examples.
4*/
5
6/* Create Imagick objects */
7$Imagick = new Imagick();
8
9/* Create ImagickDraw objects */
10$ImagickDraw = new ImagickDraw();
11
12/* Create ImagickPixel objects */
13$ImagickPixel = new ImagickPixel();
14
15/* This array contains polygon geometry */
16$array = array( array( "x" => 378.1, "y" => 81.72 ),
17                array( "x" => 381.1, "y" => 79.56 ),
18                array( "x" => 384.3, "y" => 78.12 ),
19                array( "x" => 387.6, "y" => 77.33 ),
20                array( "x" => 391.1, "y" => 77.11 ),
21                array( "x" => 394.6, "y" => 77.62 ),
22                array( "x" => 397.8, "y" => 78.77 ),
23                array( "x" => 400.9, "y" => 80.57 ),
24                array( "x" => 403.6, "y" => 83.02 ),
25                array( "x" => 523.9, "y" => 216.8 ),
26                array( "x" => 526.2, "y" => 219.7 ),
27                array( "x" => 527.6, "y" => 223 ),
28                array( "x" => 528.4, "y" => 226.4 ),
29                array( "x" => 528.6, "y" => 229.8 ),
30                array( "x" => 528.0, "y" => 233.3 ),
31                array( "x" => 526.9, "y" => 236.5 ),
32                array( "x" => 525.1, "y" => 239.5 ),
33                array( "x" => 522.6, "y" => 242.2 ),
34                array( "x" => 495.9, "y" => 266.3 ),
35                array( "x" => 493, "y" => 268.5 ),
36                array( "x" => 489.7, "y" => 269.9 ),
37                array( "x" => 486.4, "y" => 270.8 ),
38                array( "x" => 482.9, "y" => 270.9 ),
39                array( "x" => 479.5, "y" => 270.4 ),
40                array( "x" => 476.2, "y" => 269.3 ),
41                array( "x" => 473.2, "y" => 267.5 ),
42                array( "x" => 470.4, "y" => 265 ),
43                array( "x" => 350, "y" => 131.2 ),
44                array( "x" => 347.8, "y" => 128.3 ),
45                array( "x" => 346.4, "y" => 125.1 ),
46                array( "x" => 345.6, "y" => 121.7 ),
47                array( "x" => 345.4, "y" => 118.2 ),
48                array( "x" => 346, "y" => 114.8 ),
49                array( "x" => 347.1, "y" => 111.5 ),
50                array( "x" => 348.9, "y" => 108.5 ),
51                array( "x" => 351.4, "y" => 105.8 ),
52                array( "x" => 378.1, "y" => 81.72 ),
53              );
54
55/* This ImagickPixel is used to set background color */
56$ImagickPixel->setColor( 'gray' );
57
58/* Create new image, set color to gray and format to png*/
59$Imagick->newImage( 700, 500, $ImagickPixel );
60$Imagick->setImageFormat( 'png' );
61
62/* Create the polygon*/
63$ImagickDraw->polygon( $array );
64
65/* Render the polygon to image*/
66$Imagick->drawImage( $ImagickDraw );
67
68/* Send headers and output the image */
69header( "Content-Type: image/{$Imagick->getImageFormat()}" );
70echo $Imagick->getImageBlob( );
71
72?>
73