Created
February 23, 2020 05:51
-
-
Save makeding/d930565f80574744d81e216b248c230a to your computer and use it in GitHub Desktop.
一言签名档
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 | |
// 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