PHP – Membuat Shape (bangun ruang dan mewarnainya)

Ditutorial ini, bangun ruang yang akan coba kita buat ada 2, yaitu kotak, dan lingkaran.
Untuk membuat kotak dalam PHP ada fungsi khusus bernama imagerectangle();

<?php
header("Content-type:image/jpeg");
$gb= imagecreate(500,500);
$bg_color= imagecolorallocate($gb,255,255,255);
$border= imagecolorallocate($gb,0,0,0);
$text_color= imagecolorallocate($gb,255,0,0);
$text = "100x100";
imagestring($gb,14,30,70,$text,$text_color);
imagerectangle($gb,20,50,120,150,$border);
imagejpeg($gb);
imagedestroy($gb);
?>

Preview untuk kode di atas adalah :

Untuk mewarnai kotak, ada fungsi khusus yang juga telah diciptakan dalam PHP yaitu : imagefilledrectangle();

 
<?php
header("Content-type:image/jpeg");
$gb= imagecreate(500,500);
$bg_color= imagecolorallocate($gb,255,255,255);
$warna1= imagecolorallocate($gb,145,2,154);
$warna2= imagecolorallocate($gb,78,87,0);
$border= imagecolorallocate($gb,0,0,0);
imagerectangle($gb,20,50,120,150,$border);
imagefilledrectangle($gb,20,50,120,100,$warna1);
imagefilledrectangle($gb,20,100,120,150,$warna2);
imagejpeg($gb);
imagedestroy($gb);
?>

Preview untuk kode di atas adalah :

Untuk menciptakan objek lingkaran, digunakan fungsi imageellipse();

 
<?php
header("Content-type:image/jpeg");
$bg= imagecreate(500,500);
imagecolorallocate($bg,255,255,255);
$line= imagecolorallocate($bg,0,0,0);
$color = imagecolorallocate($bg,201,5,33);
imageellipse($bg,50,50,100,100,$line);
imagefilledellipse($bg,50,50,100,100,$color);
imagejpeg($bg);
imagedestroy($bg);
?>

Preview Untuk kode di atas adalah :

About Lin

SG | ID | Illustrator | Beauty Blogger | Skincare anthusiast

Posted on 26 May 2012, in Website and tagged . Bookmark the permalink. Leave a comment.

Komentar untuk penulis