php imagettftext获取模糊文本
在非常简单的解释中,我创建了一个带有库的二维码,然后将一些文本添加到此图像中 qrcode正在变好,但是当我添加文本时,无论我使用什么字体,我都会得到模糊的文本,当我打印它时,它几乎无法读取。为什么会变得模糊 这是函数(我正在试验,所以里面可能有一些愚蠢的线条)php imagettftext获取模糊文本,php,image,gd,imagettftext,Php,Image,Gd,Imagettftext,在非常简单的解释中,我创建了一个带有库的二维码,然后将一些文本添加到此图像中 qrcode正在变好,但是当我添加文本时,无论我使用什么字体,我都会得到模糊的文本,当我打印它时,它几乎无法读取。为什么会变得模糊 这是函数(我正在试验,所以里面可能有一些愚蠢的线条) 公共函数CreateLabel($code$description) { 包括(getcwd().DIRECTORY_SEPARATOR.application.DIRECTORY_SEPARATOR.libraries.DIRECTO
公共函数CreateLabel($code$description)
{
包括(getcwd().DIRECTORY_SEPARATOR.application.DIRECTORY_SEPARATOR.libraries.DIRECTORY_SEPARATOR.QrCode.DIRECTORY_SEPARATOR.qrlib.php');
$qrName=preg_replace('/[^a-z0-9]+/','''''''.',strtolower($code)).png';
$src_image=D_QR.$qrName;
QRcode::png($code$src_image);
//扩展图像
列表($height,$width)=getimagesize($src_image);
$newWidth=$width+253;
$newHeight=$height+83;
$thumbnail=imagecreatetruecolor($newWidth,$newHeight);
imageantialias($缩略图,false);
$white=imagecolorallocate($thumbnail,255,255);
imagefill($缩略图,0,0,$白色);
$img_source=imagecreatefrompng($src_image);
imagecopyresampled($thumbnail,$img_source,0,87,0,0,$width,$height,$width,$height);
imagepng($thumbnail,$src_image,9);
图像销毁($img_源);
图像销毁(缩略图);
//添加文本
$image=imagecreatefrompng($src_image);
imageantialias($image,false);
imagealphablending($image,true);
$black=imagecolorallocate($image,0,0,0);
$tnr=getcwd().DIRECTORY_SEPARATOR.assets.DIRECTORY_SEPARATOR.fonts.DIRECTORY_SEPARATOR.Montserrat-Medium.otf';
$nevis=getcwd().DIRECTORY_SEPARATOR.assets.DIRECTORY_SEPARATOR.fonts.DIRECTORY_SEPARATOR.Montserrat-ExtraBold.otf';
imagettftext($image,10,085126,$black,$nevis,$code);
$max_长度=45;
如果(strlen($description)>$max_长度)
{
$newString=wordwrap($description,$max_length,“| |”);
$parts=explode(“| |,$newString”);
$x=10;
$y=20;
对于($i=0;$i)
public function CreateLabel($code, $description)
{
include(getcwd().DIRECTORY_SEPARATOR.'application'.DIRECTORY_SEPARATOR.'libraries'.DIRECTORY_SEPARATOR.'QrCode'.DIRECTORY_SEPARATOR.'qrlib.php');
$qrName = preg_replace( '/[^a-z0-9]+/', '_', strtolower($code)).'.png';
$src_image = D_QR.$qrName;
QRcode::png($code, $src_image);
//Extend Image
list($height, $width) = getimagesize($src_image);
$newWidth = $width + 253;
$newHeight = $height + 83;
$thumbnail = imagecreatetruecolor($newWidth, $newHeight);
imageantialias($thumbnail,false);
$white = imagecolorallocate($thumbnail, 255, 255, 255);
imagefill($thumbnail, 0, 0, $white);
$img_source = imagecreatefrompng($src_image);
imagecopyresampled($thumbnail, $img_source, 0, 87, 0, 0, $width, $height, $width, $height);
imagepng($thumbnail, $src_image, 9);
imagedestroy($img_source);
imagedestroy($thumbnail);
//AddText
$image = imagecreatefrompng($src_image);
imageantialias($image,false);
imagealphablending($image, true);
$black = imagecolorallocate($image, 0, 0, 0);
$tnr = getcwd().DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'fonts'.DIRECTORY_SEPARATOR.'Montserrat-Medium.otf';
$nevis = getcwd().DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'fonts'.DIRECTORY_SEPARATOR.'Montserrat-ExtraBold.otf';
imagettftext($image, 10, 0, 85,126, $black, $nevis, $code);
$max_length = 45;
if (strlen($description) > $max_length)
{
$newString = wordwrap($description, $max_length, "||");
$parts = explode("||", $newString);
$x = 10;
$y = 20;
for($i = 0; $i <= sizeof($parts); $i++)
{
imagettftext($image, 9, 0, $x, $y*($i+1), $black, $tnr, $parts[$i]);
//imagestring($image, $f, $x, $y*($i+1), $parts[$i], $black*-1);
}
}
else imagettftext($image, 9, 0, 12, 20, $black*-1, $tnr, $description);
imageantialias($image,false);
imagepng($image, $src_image, 9);
imagedestroy($image);
return $qrName;
}