Jump to content

Can true type fonts be used to write over png images


deva

Recommended Posts

Hi,

 

I used imagecreatefrompng("ur.png"),

and created a png image. Function imagettftext($im, $fontsize, $angle, $xc, $yc, $txtcolor, $fontfamily, $text); does not work here. Can i use imagettftext() if i create png images using imagecreatefrompng()? Could any one advise..

 

thanks,

deva

thanks FD and Yesideez.. yes i uploaded the font.. the function imagettftext() works well when i use imagecreate(100,100) function. But when i use imagecreatefrompng("ur.png") function, i was able to use only imagestring() function which takes ".gdf" fonts. But i wish to use, ttf fonts. Hence, i like to know, whether its possible to use imagettftext() function while using imagecreatefrompng() function.

 

thanks,

deva

I've not tried it but I have been thinking of doing it myself as I've just written a routine to generate a random image containing random characters. Having a patterned background is more secure than using a plain background although I am using random colors for each letter and I'm also changing the rotation of each character.

 

Example:

makeimg.php

hi Yesideez, please see my below code..

<?php

$im = imagecreatefrompng("1.png");

$txtcol = imagecolorallocate($im, 255, 255, 0);

$height = imagesy($im);

$font=imageloadfont("anticlimax.gdf");

$text = "Hi World";

$leftPos = 10;

imagestring($im, $font, $leftPos, $height-20, $text, $txtcol);

Header('Content-type: image/png');

imagepng($im);

imagedestroy($im);

?>

 

The above code works fine for me.. but i like to use ttf fonts instead of gdf fonts.. as below, but i dont get result. Advise any change below..

 

<?php

$im=imagecreatefrompng("1.png");

$font="egyptien.ttf";

$leftPos=10;

$height=imagesy($im);

$size=5;

$angle=0;

$text="Hi World";

$txtcol=imagecolorallocate($im, 255, 255, 0);

imagettftext($im, $size, $angle, $leftPos, $height-20, $txtcol, $font, $text);

header("Content-type: image/png");

imagepng($im);

imagedestroy($im);

?>

 

thanks,

deva

I uploaded this to my web space:

<?php
$im=imagecreatefrompng("includes/gfx/codebg.png");
$font="includes/fonts/times.ttf";
$leftPos=10;
$height=imagesy($im);
$size=10;
$angle=0;
$text="Hi World";   
$txtcol=imagecolorallocate($im, 255, 255, 0);
imagettftext($im, $size, $angle, $leftPos, $height-20, $txtcol, $font, $text);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>

 

It produces this:

help.php

 

I suggest you check and make sure the paths and names of your PNG and TTF file are correct.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.