<?php
error_reporting(0);
include('FarsiGD.php');
function circleWaterMark($imagex,$imagey){
    if(empty($imagex) || empty($imagey))
        throw new Error();
    $imX = imagecreatefromstring(file_get_contents($imagex)) or die();
    $imY = imagecreatefromstring(file_get_contents($imagey)) or die();
    list($source_width, $source_height, $source_type) = getimagesize($imagey);
    list($w, $s, $source_type) = getimagesize($imagex);
    $corner_image = imagecreatetruecolor($source_width,$source_height);
    $clear_colour = imagecolorallocate($corner_image,255,0,255);
    imagecolortransparent($imY,$clear_colour);
    $clear_colour = imagecolorallocate($imX,000,000,255);
    imagecolortransparent($imX,$clear_colour);
    $mask = imagecreatetruecolor($source_width, $source_height);
    $black = imagecolorallocate($mask, 0, 0, 0);
    $magenta = imagecolorallocate($mask, 255, 0, 255);
    imagefill($mask, 0, 0, $magenta);
    imagefilledellipse($mask,$source_width / 2,$source_height / 2,$source_width+5,$source_height,$black);
    imagecolortransparent($mask, $black);
    imagecopymerge($imY,$mask,0,0,0,0,$source_width,$source_height,100);
    $final_img = imagecreatetruecolor($w, $s);
    imagealphablending($final_img, true);
    imagesavealpha($final_img, true);
    imagecopy($final_img, $imY, 315, 170, 0, 0, $source_width, $source_height);
    imagecopy($final_img, $imX, 0, 0, 0, 0, $w, $s);
    return $final_img;
}
function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, $fontfile, $text, $px) {
    for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
        for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
            $bg = imagettftext($image, $size, $angle, $c1, $c2, $fontfile, $text);
        return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
}
function convertEnglishToPersian($string1) {
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
$english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

$output= str_replace($english, $persian, $string1);
return $output;
}
header('content-type:image/jpeg');
$image = circleWaterMark('ch.jpg','ch.jpg');
$a = substr(number_format($_GET['Amount']),0,15); //Amount
$b =  substr(mb_substr($_GET['Cardm'],0,4).'-'.mb_substr($_GET['Cardm'],4,2)."**-****-".mb_substr($_GET['Cardm'],12,16),0,100);
$c =  substr(mb_substr($_GET['Cardg'],0,4).'-'.mb_substr($_GET['Cardg'],4,2)."**-****-".mb_substr($_GET['Cardg'],12,16),0,100);
$fontFile = 'IRANSansWeb.ttf'; // تغییر فونت ! 

$result = json_decode(file_get_contents("https://api.codebazan.ir/time-date/?json=fa"),true)['result'];
$time = $result['date'].' '.$result['time'];
$yellow = imagecolorallocate($image,158 ,158 ,158);
$FaGD = new FarsiGD();
imagettfstroketext($image,25,0,5,533,$yellow,$fontFile,$time,3); //Time
imagettfstroketext($image,25,0,5,1275,$yellow,$fontFile,($a),3); //Amount
imagettfstroketext($image,25,0,5,680,$yellow,$fontFile,($b),3); //Cardm
imagettfstroketext($image,25,0,5,830,$yellow,$fontFile,($c),3); //Cardg 
$h1 = $FaGD->persianText(json_decode(file_get_contents("https://api.zprogramming.org/web/cool/bankinfo/".$_GET['Cardg']),true)['infos']['name_fa'],'en','normal'); //bank
imagettfstroketext($image,25,0,5,1125,$yellow,$fontFile,$h1,3); //bank
imagettfstroketext($image,25,0,5,1425,$yellow,$fontFile,(rand(111111111111,999999999999)),3); //Code 
$h = $FaGD->persianText($_GET['Name'],'en','normal'); //Name
imagettfstroketext($image,25,0,5,973,$yellow,$fontFile,$h,3); //Name
imagejpeg($image);
?>