Skip to content

Instantly share code, notes, and snippets.

@makeding
Created February 23, 2020 05:51
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 makeding/d930565f80574744d81e216b248c230a to your computer and use it in GitHub Desktop.
Save makeding/d930565f80574744d81e216b248c230a to your computer and use it in GitHub Desktop.
一言签名档
<?php
// download hitokoto.json from https://github.com/kokororin/hitokoto
$hitokoto = json_decode(file_get_contents('./hitokoto.json'),true);
$h = $hitokoto[array_rand($hitokoto)];
$hh = $h['hitokoto'];
$count = mb_strlen($hh,'UTF-8');
$height = $count * 27;
$width = 30;
$line = 1;
//换行还是有点bug 不想思考了
if($count > 30){
$height = 800;
$line = ceil($count / 30);
$width = 30 * $line;
}
$image = imagecreate($height, $width);
$bg = imagecolorallocate($image, 255, 255, 255);
$font = './1.TTF';
$black = imagecolorallocate($image, 0, 0, 0);
imagecolortransparent($image,$bg);
header('Content-type: image/png');
for ($i=0; $i < $line ; $i++) {
$t = mb_substr($hh,0,30);
$hh = str_replace($t,'',$hh);
imagettftext($image, 20, 0, 1, $i * 28 + 25, $black, $font, $t);
}
imagepng($image);
imagedestroy($image);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment