Jump to content

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.

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.