我正在将文本转换为图像,以便用户可以直接在Facebook和Twitter上分享报价 我想用php gd制作图像。我有这个代码工作正常,但它有一些问题,如长线不会自动断开。此外,字体不起作用,因为我想使用宇宙字体。
这是我的代码
<?php
header("Content-type: image/png");
$string = ' <p>I think the whole under-eye-bag thing is hereditary, and I just got lucky.</p> <p class="bq_fq_a"> <a id="qut" title="julianna_margulies"> Julianna Margulies </a> </p> <br>';
$font = '12';
$fonttype = '/path/cosmic.TTF';
$width = imagefontwidth($font) * strlen($string);
$height = imagefontheight($font);
$image = imagecreatetruecolor ($width,$height);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$white);
imagestring ($image,$font,0,0,$string,$black);
imagepng ($image);
imagedestroy($image);
?>