Skip to content

Instantly share code, notes, and snippets.

@gvgvgvijayan
Last active December 22, 2019 12:15
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 gvgvgvijayan/3760ae723716b66c1ce1e0612c5d557e to your computer and use it in GitHub Desktop.
Save gvgvgvijayan/3760ae723716b66c1ce1e0612c5d557e to your computer and use it in GitHub Desktop.
<?php
$wide = 1080;
$height = 50;
$handle = imagecreatetruecolor($wide, $height); #create a 640px wide 480px height image. Consider this like canvas to draw.
$green = imagecolorallocate($handle, 0, 255, 0); #assign green color
$black = imagecolorallocate($handle, 0, 0, 0); #assign black color
imagefilledrectangle($handle, 0, 0, $wide, $height, $green); #Create filled rectangle with green color. Consider like this the shape drawn over the canvas.
imagestring($handle, 5, intval($wide/2) - 30, intval($height/2) - 8, rand_string(), $black);
imagestring($handle, 5, 0, intval($height/2) + 8, date(DATE_ATOM , $_SERVER['REQUEST_TIME']), $black);
# Jpeg conversion
header("Content-type: image/jpg");
imagejpeg($handle);
imagedestroy($handle); #Destroy the image handle to free up the resource
/*Helper Section*/
function rand_string($length = 6)
{
$master_list = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
shuffle($master_list);
$sub_element = array_slice($master_list, 0, $length);
$to_string = implode($sub_element);
return $to_string;
}
/*Helper Section End*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment