Skip to content

Instantly share code, notes, and snippets.

@MarkVaughn
Created April 12, 2018 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkVaughn/c93c4e5005edea6909038f34dbe97a75 to your computer and use it in GitHub Desktop.
Save MarkVaughn/c93c4e5005edea6909038f34dbe97a75 to your computer and use it in GitHub Desktop.
Simple random image
<?php
function randomImage(int $width, int $height)
{
$image = imagecreatetruecolor($width, $height);
for($row = 1; $row <= $height; $row++) {
for($column = 1; $column <= $width; $column++) {
$red = mt_rand(0,255);
$green = mt_rand(0,255);
$blue = mt_rand(0,255);
$colour = imagecolorallocate ($image, $red , $green, $blue);
imagesetpixel($image, $column - 1 , $row - 1, $colour);
}
}
header('Content-type: image/png');
return imagepng($image);
}
@MarkVaughn
Copy link
Author

Example result
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment