我通过在图像上附加名称来生成图像,但韩文文字显示不正确。
我尝试在html上添加<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
,但无法查看준석 김
我有以下函数,我用ajax调用生成图像。
public function CreateMyCertificate()
{
if (Auth::check()) {
$MyScratchProjects = new MyScratchProjects();
if(ctype_digit($_POST['id'])) {
if(isset($_POST['id']) && !empty($_POST['id'])) {
$DiplomaIdx = $_POST['id'];
} else {
$DiplomaIdx = "0";
}
$GetMyDiploma = $MyScratchProjects->GetMyDiploma($DiplomaIdx);
$CertificatePath = url().'/public/upload/diplomas/certificate/'.$GetMyDiploma[0]->CertificateTemplate; // Get certificate
$FileExt = pathinfo($CertificatePath, PATHINFO_EXTENSION);
$Name = $GetMyDiploma[0]->FirstName.' '.$GetMyDiploma[0]->LastName; // Get user first & last name
$CertificateName = strtolower($GetMyDiploma[0]->Title).'-certificate'; // Get user first & last name
//$Name = "Wonkyu Kim";
$SourceFile = $CertificatePath;
//Set the Content Type
//header('Content-type: image/jpeg');
// Copy and resample the imag
list($Width, $Height) = getimagesize($SourceFile);
$ImageP = imagecreatetruecolor($Width, $Height);
if (strtolower($FileExt) == 'png') {
$Image = imagecreatefrompng($SourceFile);
} else if(strtolower($FileExt) == 'jpeg') {
$Image = imagecreatefromjpeg($SourceFile);
} else if(strtolower($FileExt) == 'gif') {
$Image = imagecreatefromgif($SourceFile);
} else {
$Image = imagecreatefromjpeg($SourceFile);
}
imagecopyresampled($ImageP, $Image, 0, 0, 0, 0, $Width, $Height, $Width, $Height);
// Prepare font size and colors
$TextColor = imagecolorallocate($ImageP, 129, 112, 167);
$BgColor = imagecolorallocate($ImageP, 129, 112, 167);
$Font = 'resources/assets/front/fonts/Roboto-Bold-webfont.ttf';
$FontSize = 27;
// Set the offset x and y for the text position
$OffsetX = 0;
$offsetY = 20;
// Get the size of the text area
$Dims = imagettfbbox($FontSize, 0, $Font, $Name);
$TextWidth = $Dims[4] - $Dims[6] + $OffsetX;
$TextHeight = $Dims[3] - $Dims[5] + $offsetY;
// Add text
//imagettftext($ImageP, $FontSize, 0, $OffsetX, $offsetY, $TextColor, $Font, $text);
imagettftext($ImageP, $FontSize, 0, 270, 215, $TextColor, $Font, $Name);
// Save the picture
ob_start();
imagepng($ImageP);
$Base64ImgData = base64_encode(ob_get_clean());
$html = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" /><div class="modal-body">
<div class="certificate_model_container">
<div class="model_inner_container">
<div class="find_inner_logo">
<img alt="edito" src="'.url().'/resources/assets/front/images/Logo_inner.png">
<h5>'.$GetMyDiploma[0]->Title.'</h5>
</div>
<div class="model_img_dv">';
$html .= '<a href="data:image/png;base64,'.$Base64ImgData.'" class="none download-my-certificate" download="'.$CertificateName.'.png"></a>';
$html .= '<img class="myImage" src="data:image/png;base64,'.$Base64ImgData.'" alt="'.$GetMyDiploma[0]->Title.'">';
$html .= '<p>'.MyFuncs::DateFormat($GetMyDiploma[0]->AwardedOn).'</p>
</div>
</div>
</div>
</div>
<div class="modal-footer regiter_btns img_certi_ftr">
<div class="find_acc_btn_contianer re_container">
<button class="download" type="button">'.trans('messages.my_story.download').'</button>
<button class="btn_2" type="button">'.trans('messages.my_story.print').'</button>
<button data-dismiss="modal" class="" type="button">'.trans('messages.my_story.close').'</button>
</div>
</div>';
// Clear
imagedestroy($Image);
imagedestroy($ImageP);
echo $html;
}
}