<?php
if(isset($_GET['VoucherNo']) && $_GET['VoucherNo']!="")
$VoucherNo=$_GET['VoucherNo']; 

if(isset($_GET['ExpiryDate']) && $_GET['ExpiryDate']!="")
$ExpiryDate=$_GET['ExpiryDate']; 


if(isset($_GET['CustomerName']) && $_GET['CustomerName']!="")
$CustomerName=$_GET['CustomerName']; 


if(isset($_GET['eVoucherNumber']) && $_GET['eVoucherNumber']!="")
$eVoucherNumber=$_GET['eVoucherNumber']; 

if(isset($_GET['w']) && $_GET['w']>0)
$w=$_GET['w'];
else
$w='100%';


if(isset($_GET['h']) && $_GET['h']>0  && $_GET['h']!="")
$h=$_GET['h']; 
else
$h='200%';


if($w<1 || $h<1 || $w=="" || $h=="")
{
$w='100%';
$h='200%';
}
$VoucherTypeCode=3524;
$partnerCode=378;
$img="http://mutakamela.ddns.net:53557/erp/images/".$VoucherTypeCode.'-'.$partnerCode.".jpg";
?>

<!-- <img id="scream" src="<?php echo $img;?>" style="display: none;" width=100% height="100%">
  <img  id="qrcode" style="width:100px !important;display: block;" src="#"> 
  <canvas id="myCanvas" width="705" height="1012"
style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>  -->
<script type="text/javascript">
//https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=54356345634564565465656
/*    var img = document.getElementById("scream");
   // let img = new Image();
 //   img.src=s2;
window.onload = function() {
  
var canvas = document.getElementById("myCanvas");

    var ctx = canvas.getContext("2d");
    //    var partnerCode = document.getElementById("partnerCode").value;
//setTimeout(function(){ alert("Hello"); }, 1000);

   // img.src=s2;
    var img = document.getElementById("scream");
    var img2 = document.getElementById("qrcode");
    

//let image = new Image();
//image.crossOrigin = "anonymous";
    var s1='https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=<?php echo $eVoucherNumber;?>';
   //img2.style.display='block';
    //qrcode
    let image = new Image();

    img2.src=s1;
   image.src=s1;
       console.log(img2.src);
    var img2 = document.getElementById("qrcode");
//var  image=new Image();
image=img2;
   // alert
// canvas.height = canvas.width * (img.height / img.width);

//        ctx.globalCompositeOperation="source-in";

  // ctx.drawImage(img, 10, 10,705,1000);
      ctx.drawImage(image, 0,0,100,100);
    ctx.font = "18pt Arial";
    ctx.fillStyle = 'red';
	ctx.fillText('<?php echo $CustomerName;?>', 25, 360);


    ctx.font = "Bold 12pt Arial";
    ctx.fillStyle = 'Black';
	ctx.fillText('Expiry Date :<?php echo $ExpiryDate;?>', 25, 379);

   // img2.style.display='none';
    ctx.font = "Bold 12pt Arial";
    ctx.fillStyle = 'Green';
	ctx.fillText('Voucher  #:<?php echo $VoucherNo;?>', 215, 379);
};*/
</script>
<?php   
 //watermark($img, "hello");
function watermark($sourcefile, $watermarkfile) {
 
    #
    # $sourcefile = Filename of the picture to be watermarked.
    # $watermarkfile = Filename of the 24-bit PNG watermark file.
    #
   
    //Get the resource ids of the pictures
    $watermarkfile_id = imagecreatefrompng($watermarkfile);
   
    imageAlphaBlending($watermarkfile_id, false);
    imageSaveAlpha($watermarkfile_id, true);

    $fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));

    switch($fileType) {
        case('gif'):
            $sourcefile_id = imagecreatefromgif($sourcefile);
            break;
           
        case('png'):
            $sourcefile_id = imagecreatefrompng($sourcefile);
            break;
           
        default:
            $sourcefile_id = imagecreatefromjpeg($sourcefile);
    }

    //Get the sizes of both pix  
  $sourcefile_width=imageSX($sourcefile_id);
  $sourcefile_height=imageSY($sourcefile_id);
  $watermarkfile_width=imageSX($watermarkfile_id);
  $watermarkfile_height=imageSY($watermarkfile_id);

    $dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
    $dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
   
    // if a gif, we have to upsample it to a truecolor image
    if($fileType == 'gif') {
        // create an empty truecolor container
        $tempimage = imagecreatetruecolor($sourcefile_width,
                                                                            $sourcefile_height);
       
        // copy the 8-bit gif into the truecolor image
        imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0,
                            $sourcefile_width, $sourcefile_height);
       
        // copy the source_id int
        $sourcefile_id = $tempimage;
    }

    imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,
                        $watermarkfile_width, $watermarkfile_height);

    //Create a jpeg out of the modified picture
    switch($fileType) {
   
        // remember we don't need gif any more, so we use only png or jpeg.
        // See the upsaple code immediately above to see how we handle gifs
        case('png'):
            header("Content-type: image/png");
            imagepng ($sourcefile_id);
            break;
           
        default:
            header("Content-type: image/jpg");
            imagejpeg ($sourcefile_id);
    }          
 
    imagedestroy($sourcefile_id);
    imagedestroy($watermarkfile_id);
   
}
//header('Content-type: image/png');

//include('evoucherprint.html?VoucherNo=REQ-0000006&ExpiryDate=2021-11-21&CustomerName=Abdullah%202&eVoucherNumber=7DFF3FB8')
     /*   $ch = curl_init();
        $googleChartAPI = 'http://mutakamela.ddns.net:53557/othererp/portal/report_files/evoucherprint.html?VoucherNo=REQ-0000006&ExpiryDate=2021-11-21&CustomerName=Abdullah%202&eVoucherNumber=7DFF3FB8';
        curl_setopt($ch, CURLOPT_URL, $googleChartAPI);
      //  curl_setopt($ch, CURLOPT_POST, true);
        //curl_setopt($ch, CURLOPT_POSTFIELDS, "VoucherNo=REQ-0000006&ExpiryDate=2021-11-21&CustomerName=Abdullah%202&eVoucherNumber=7DFF3FB8");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $img = curl_exec($ch);
        curl_close($ch);
    	
        if($img) {
            if($filename) {
                if(!preg_match("#\.png$#i", $filename)) {
                    $filename .= ".png";
                }
                
                return file_put_contents($filename, $img);
            } else {
                header("Content-type: image/png");
                print $img;
              //  return  $img;
            }
        }*/
  
echo "<script>window.location='evoucherprint.html?VoucherNo=$VoucherNo&ExpiryDate=$ExpiryDate&CustomerName=$CustomerName&eVoucherNumber=$eVoucherNumber'</script>";
/*
echo "<iframe src='evoucherprint.html?VoucherNo=".$VoucherNo."&ExpiryDate=".$ExpiryDate."&CustomerName=".$CustomerName."&eVoucherNumber=".$eVoucherNumber."' width='$w' height='".$h."'>";*/
?>
