ramiwahdan Posted May 22, 2020 Share Posted May 22, 2020 (edited) Hi, I am generating certificates in php i can display the name in arabic but it will not print on the certicate. It can show the English names though! is there a special code to be able to show that? code: <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <title>Certificate Generator</title> </head> <body> <center> <br><br><br> <h3>Certificate Generator</h3> <br><br><br><br> <form method="post" action=""> <div class="form-group col-sm-6"> <input type="text" name="name" class="form-control" id="name" placeholder="Enter Name Here..."> </div> <button type="submit" name="generate" class="btn btn-primary">Generate</button> </form> <br> <?php if (isset($_POST['generate'])) { $name = strtoupper($_POST['name']); $name_len = strlen($_POST['name']); if ($name == "" ) { echo " <div class='alert alert-danger col-sm-6' role='alert'> Ensure you fill all the fields! </div> "; }else{ echo " <div class='alert alert-success col-sm-6' role='alert'> Congratulations! $name on your excellent success. </div> "; //designed certificate picture $image = "certi.png"; $createimage = imagecreatefrompng($image); //this is going to be created once the generate button is clicked $output = "certificate.png"; //then we make use of the imagecolorallocate inbuilt php function which i used to set color to the text we are displaying on the image in RGB format $white = imagecolorallocate($createimage, 205, 245, 255); $black = imagecolorallocate($createimage, 0, 0, 0); //Then we make use of the angle since we will also make use of it when calling the imagettftext function below $rotation = 0; //we then set the x and y axis to fix the position of our text name $origin_x = 200; $origin_y=240; //we then set the x and y axis to fix the position of our text occupation $origin1_x = 120; $origin1_y=90; //we then set the differnet size range based on the lenght of the text which we have declared when we called values from the form if($name_len<=7){ $font_size = 25; $origin_x = 190; } elseif($name_len<=12){ $font_size = 30; } elseif($name_len<=15){ $font_size = 26; } elseif($name_len<=20){ $font_size = 18; } elseif($name_len<=22){ $font_size = 15; } elseif($name_len<=33){ $font_size=11; } else { $font_size =10; } $certificate_text = $name; //font directory for name $drFont = dirname(__FILE__)."/developer.ttf"; //function to display name on certificate picture $text1 = imagettftext($createimage, $font_size, $rotation, $origin_x, $origin_y, $black,$drFont, $certificate_text); imagepng($createimage,$output,3); ?> <!-- this displays the image below --> <img src="<?php echo $output; ?>"> <br> <br> <!-- this provides a download button --> <a href="<?php echo $output; ?>" class="btn btn-success">Download My Internship Certificate</a> <br><br> <?php } } ?> </center> <footer> <center><p>Built with ❤ by <a href="https://olawanlejoel.github.io/portfolio/">Olawanle Joel</a></p></center> </footer> <!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> </body> </html> Edited May 22, 2020 by ramiwahdan typo error Quote Link to comment Share on other sites More sharing options...
Barand Posted May 22, 2020 Share Posted May 22, 2020 Try a change of font. It works with "calibri" <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = imagecreatetruecolor(500,100); $tcolor = imagecolorallocate($im,255,255,255); imagettftext($im, 20, 0, 20, 60, $tcolor, 'c:/windows/fonts/calibri.ttf', $name); header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?> result Quote Link to comment Share on other sites More sharing options...
ramiwahdan Posted May 22, 2020 Author Share Posted May 22, 2020 Thanks but as you can see the letters are not connected with each other. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2020 Share Posted May 23, 2020 Plan B - vector graphics <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = "<svg width='500' height='100'> <rect x='1' y='1' width='499' height='99' style='fill:#000; stroke:#000' /> <text x='20' y='60' style='font-family:calibri; font-size:30pt; fill:#FFF;'>$name</text> </svg> "; echo $im; ?> Quote Link to comment Share on other sites More sharing options...
ramiwahdan Posted May 23, 2020 Author Share Posted May 23, 2020 Thanks, When i put this in image it gives me your code instead of name: $name = strtoupper($_POST['name']); $name_len = strlen($_POST['name']); $im= "<svg width='500' height='100'> <rect x='1' y='1' width='499' height='99' style='fill:#000; stroke:#000' /> <text x='20' y='60' style='font-family:calibri; font-size:30pt; fill:#FFF;'>$name</text> </svg> "; $certificate_text = $im; //function to display name on certificate picture $text1 = imagettftext($createimage, $font_size, $rotation, $origin_x, $origin_y, $black, 'c:/windows/fonts/calibri.ttf', $certificate_text); i am getting the code for $im instead! I need to get the name there. Quote Link to comment Share on other sites More sharing options...
ramiwahdan Posted May 23, 2020 Author Share Posted May 23, 2020 i need to get the name in arabic but connected together and inside the certificate which should be شهد Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2020 Share Posted May 23, 2020 Plan C - Embed the png image in the svg image and overlay with the name <?php $name = 'لقمان ابراهيم عباس عجلان'; $im = "<svg width='500' height='500'> <image x='0' y='0' width='500' height='500' xlink:href='images/snowman.png' /> <text x='250' y='110' text-anchor='middle' style='font-family:calibri; font-size:30pt; fill:#FFF;'>$name</text> </svg> "; echo $im; ?> 1 Quote Link to comment Share on other sites More sharing options...
ramiwahdan Posted May 23, 2020 Author Share Posted May 23, 2020 Thanks it works now, if i right click on the image to save then it saves as html not image. is there a way to add a button under the image to download the certificate or print it? Quote Link to comment Share on other sites More sharing options...
ramiwahdan Posted May 23, 2020 Author Share Posted May 23, 2020 or if i can just click the image as the one you have above then it can save it as image or print it. Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2020 Share Posted May 23, 2020 If you want to print then I would take the pdf route, placing the png image in the output then, again, overwriting the text. TCPDF appears to support Arabic Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2020 Share Posted May 23, 2020 I downloaded the class and gave it a try. This creates a pdf doc with a separate page (image and name) for each person. <?php require '../tcpdf/tcpdf.php'; $names = [ "ماشوت محمد علي علام" , "منى طه أبو العلا شعلان" , "وليد عبد العزيز السيد الشيخ" , "ابراهيم عبد السلام خلف" , "احمد حمدى نوار" ]; $pdf = new tcpdf(); $pdf->SetFont('aefurat', '', 30); $pdf->SetTextColor(255); foreach ($names as $name) { $pdf->AddPage(); $pdf->Image('images/snowman.png',15,15,180,180); $pdf->setY(40); $pdf->cell(0,15,$name,0,1,'C'); } $pdf->output('Sample.pdf', 'I'); ?> Output (greatly reduced) 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.