I've used it and it's working way better then ar-php and other libraries over the internet but this too is messing with some characters to be printed on the image,
public function createVGImage(Request $data)
{
$dateIslamic = $data->islamic_calender;
$dateEnglish = $data->date_recorded;
$city = $data->cityName;
$place = $data->placeName;
$nameOfImg = $this->generalService->generateRandomString();
$nameOfImg = $nameOfImg.'.png';
// $text = ' 5 ربیع الاول 1439';
$text = $dateIslamic;
persian_log2vis($text);
// $text1 = '24 December 2017';
$text1 = $dateEnglish;
persian_log2vis($text1);
// $text2 = 'ملتان پاکستان';
$text2 = $place.' '.$city;
persian_log2vis($text2);
if($data->group_type == 1) {
// Create the image
$im = imagecreatefromjpeg(public_path() . '/assets/client/images/sample1.jpg');
} else {
$im = imagecreatefromjpeg(public_path() . '/assets/client/images/sample2.jpg');
}
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$yellow = imagecolorallocate($im, 248, 255, 0);
$bg_color = imagecolorallocate($im, 255, 255, 255);
// Replace path by your own font path
$font = public_path().('/assets/client/p21/DejaVuSans.ttf');
// Add the text
@imagettftext($im, 100, 0, 140, 600, $white, $font, $text);
@imagettftext($im, 50, 0, 350, 800, $white, $font, $text1);
@imagettftext($im, 100, 0, 300, 1050, $yellow, $font, $text2);
// Set the content-type
// header("Content-type: image/png");
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im, "uploads/".$nameOfImg);
imagedestroy($im);
return collect([
'collect' => 'success',
'name' => $nameOfImg
]);
}
Please look into it, or may be suggest me some solution to get this done as well.