Jump to content

Name in arabic not displayed


ramiwahdan

Recommended Posts

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 &#10084; 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 by ramiwahdan
typo error
Link to comment
Share on other sites

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

image.png.ce19524da0eef5a5212b0a0b4b6bed9e.png

Link to comment
Share on other sites

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;
?>

image.png.92f841bf50c9ad2db2eccccea6ab9420.png

Link to comment
Share on other sites

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.

certificate.png

Link to comment
Share on other sites

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;
?>

image.png.0ea2da2ee8e8b136fbb7117bb78be4db.png

  • Thanks 1
Link to comment
Share on other sites

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)

image.thumb.png.d3e89ddcf34833a1738dce8ffb52efab.png

  • Great Answer 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.