How to draw shapes in php

Advertisemen

Let's start by drawing a line first.

<?php
   
$width = 500;
   
$height = 200;
   
$img = ImageCreateTrueColor($width, $height);
   
$background_color = 0xFFFFFF; // white

   
ImageFilledRectangle($img, 0, 0, $width - 1,
       
$height - 1, $background_color);

   
imagesetthickness($img, 5);

   
$x1 = $y1 = 10 ;
   
$x2 = $y2 = $height - 1;
   
$color = 0xCCCCCC; // gray

   
ImageLine($img, $x1, $y1, $x2, $y2, $color);

   
header('Content-type: image/png');
   
ImagePNG($img);
   
ImageDestroy($img);
?>

There are nothing much to explain here because most of them are pretty self explanatory.
ImageFilledRectange creates a rectangle with height of 199px (200-1) and width of 499px (500-1) then we create line using ImageLine function, line starts at (x1, y1) = 10 and ends at (x2, y2) = 499.

This should print out the image like this :


Replace ImageLine($img, $x1, $y1, $x2, $y2, $color) with :
ImageRectangle($img, $x1, $y1, $x2, $y2, $color); if you want to create rectangle.


ImageFilledRectangle($img, $x1, $y1, $x2, $y2, $color); if you want to create filled rectangle.
$points = array($x1, $y1, $x2, $y2, $x3, $y3);
ImagePolygon($img, $points, count($points)/2, $color); if you want to draw a polygon.
$points = array($x1, $y1, $x2, $y2, $x3, $y3); 
ImageFilledPolygon($img, $points, count($points)/2, $color);  if you want to draw filled polygon.
Thanks....

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D