Created
April 30, 2019 12:06
-
-
Save andreaganduglia/ed334f95c5f66a62b174428eb50c8a9e to your computer and use it in GitHub Desktop.
Create image with solid background and random polygons with PHP and GD Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// set image width and height | |
$w = 400; | |
$h = 300; | |
// randoms coords for polygons | |
$coords = []; | |
foreach(range(0,127) as $p){ | |
$coords[] = rand(0,$w); | |
$coords[] = rand(0,$h); | |
} | |
// create image | |
$image = imagecreatetruecolor($w, $h); | |
// fill the background | |
imagefilledrectangle($image, 0, 0, $w, $h, imagecolorallocate($image, mt_rand(0,255) , mt_rand(0,255) , mt_rand(0,255))); | |
// draw some polygons | |
imagefilledpolygon($image, $coords, 48, imagecolorallocate($image, mt_rand(0,255) , mt_rand(0,255) , mt_rand(0,255))); | |
imagefilledpolygon($image, $coords, 24, imagecolorallocate($image, mt_rand(0,255) , mt_rand(0,255) , mt_rand(0,255))); | |
header('Content-type: image/png'); | |
imagepng($image); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment