0

im trying to make a form with php and gd library. form contains a png logo with transparent packgroung. now i have 3 problems:

  1. when i make a border then i want to place the logo in top corner of image, its not transparented background anymore

  2. im using persian font and using imagettftext function. it show the characters but in persian we have merged words but it show characters seperated

  3. how can i draw rounded corner borders

here is my code:

$fontSize=4;
$width = imagefontwidth($font) * strlen($string)+10 ;
$height = imagefontheight($font) ;


$handle = ImageCreate (800, 400) or die ("Cannot Create image");
$logo = imagecreatefrompng( 'Logo.png' );

$bg_color = ImageColorAllocate ($handle, 255, 240, 250);
$txt_color = ImageColorAllocate ($handle, 0, 0, 0);

$title="فرم قرارداد";
$font = "IRANSans.ttf";
$title_size = 18;
imagettftext( $handle, $title_size, 0, 620, 100, $txt_color, $font, $title );

$black = imagecolorallocate($handle, 0, 0, 0);
imagerectangle($handle, 20, 20, 780, 380, $black);
imagecopy($handle, $logo, 10, 10, 0, 0, 161, 160);

  header('Content-Type: image/png');
    imagepng($handle);
hsoft
  • 49
  • 7

1 Answers1

0
  1. See this answer: php GD create a transparent png image
  2. You'll have to use an OpenType (.otf) font, if you want to make use of your language's typographic characteristics.
  3. You might want to take a look at GD's imagearc.
Ro Achterberg
  • 2,504
  • 2
  • 17
  • 17
  • hi. thanks for the answer. about number 2 i convert my ttf to otf by an online tool but still get nothing – hsoft Nov 20 '18 at 14:20
  • about imagearc i searched. i think its possible to draw rounded corner square with line and arcs but it makes it hard for later changes.is there any simple function to draw square with round corners – hsoft Nov 20 '18 at 14:25
  • I'm not aware of such a function in the GD library. You may want to take a look at http://php.net/manual/en/class.imagickdraw.php. Font converters are notoriously unreliable. If I were you, I'd find a (licensed) OTF font that properly handles this for you out of the box. – Ro Achterberg Nov 21 '18 at 10:09
  • thanks again. i finaly solve the character problem with a library called persiangd.it support ttf and otf fonts.i will check your comment on imagickdraw and share the result. – hsoft Nov 21 '18 at 11:59
  • Cool, good luck. If you found my answer helpful, please consider marking it as the accepted answer :). Thank you. – Ro Achterberg Nov 21 '18 at 13:11
  • To be precise, the ImageMagick method you'll need is [ImagickDraw::roundRectangle](http://php.net/manual/en/imagickdraw.roundrectangle.php). – Ro Achterberg Nov 21 '18 at 20:26