Advertisement
sabbirshouvo

PHP GD

Jul 4th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2. //content type
  3. header('Content-Type: image/png');
  4.  
  5. //font
  6. $font = 'bangla2.ttf';
  7. $font_size = 20;
  8. $width = 640;
  9. $margin = 150;
  10. //$text = "আমার সোনার বাংলা";
  11.  
  12. $text = "   Avgvi †mvbvi evsjv Avwg ‡Zvgv‡K fv‡jvevwm";
  13.  
  14. $text_a = explode(' ', $text);
  15. $text_new = '';
  16. foreach($text_a as $word){
  17.     $box = imagettfbbox($font_size, 0, $font, $text_new.' '.$word);
  18.     if($box[2] > $width - $margin*2){
  19.         $text_new .= "\n".$word;
  20.     } else {
  21.         $text_new .= " ".$word;
  22.     }
  23. }
  24. $text_new = trim($text_new);
  25. $box = imagettfbbox($font_size, 0, $font, $text_new);
  26. $height = $box[1] + $font_size + $margin * 2;
  27.  
  28. $im = imagecreatefromjpeg('bg.jpg');
  29.  
  30. $white = imagecolorallocate($im, 255, 255, 255);
  31. $black = imagecolorallocate($im, 0, 0, 0);
  32.  
  33. imagettftext($im, $font_size, 0, $margin, $font_size+$margin, $black, $font, $text_new);
  34.  
  35. imagepng($im);
  36. imagedestroy($im);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement