Skip to content

Instantly share code, notes, and snippets.

@singleseeker
Last active August 29, 2015 14:05
Show Gist options
  • Save singleseeker/1907ef080f1ce5a4493d to your computer and use it in GitHub Desktop.
Save singleseeker/1907ef080f1ce5a4493d to your computer and use it in GitHub Desktop.
create image useing php
// Create the image
$im = imagecreatetruecolor(40, 40);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
// Set background
$rand_color= imagecolorallocate($im, rand(0,220), rand(0,220), rand(0,220));
imagefill($im, 0, 0,$rand_color);
// The text to draw
$text = '田';
// Replace path by your own font path
$font = 'fonts/SIMLI.TTF';
// Add the text
imagettftext($im, 24, 0, 4, 29, $white, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
ob_start();
imagepng($im);
$data = ob_get_clean();
file_put_contents('upload/file.png',$data);
imagedestroy($im);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment