deva Posted June 12, 2007 Share Posted June 12, 2007 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 Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/ Share on other sites More sharing options...
Full-Demon Posted June 12, 2007 Share Posted June 12, 2007 Try this: putenv('GDFONTPATH=' . realpath('.')); // use once imagettftext($im, some, values, here, 'arial', $string); // use as often as you want, remember to use the font file name without .ttf! Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273036 Share on other sites More sharing options...
Yesideez Posted June 12, 2007 Share Posted June 12, 2007 You'll need to upload the TTF font to your web space - took me a little while to figure that out! Copy one from your "C:\WINDOWS\Fonts" folder or download them. Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273037 Share on other sites More sharing options...
Full-Demon Posted June 12, 2007 Share Posted June 12, 2007 Oh yeah lol, ofcourse you have to. PHP is a server based code, so it will need the files from the server. So the server needs the files , NOT the client ofcourse. FD Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273039 Share on other sites More sharing options...
deva Posted June 12, 2007 Author Share Posted June 12, 2007 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 Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273061 Share on other sites More sharing options...
Yesideez Posted June 12, 2007 Share Posted June 12, 2007 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: Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273064 Share on other sites More sharing options...
Yesideez Posted June 12, 2007 Share Posted June 12, 2007 I just modified the script to use a PNG as the background and it isn't using it - I'm still getting a black background! ??? Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273091 Share on other sites More sharing options...
Yesideez Posted June 12, 2007 Share Posted June 12, 2007 My mistake - yes it can be done. Have you got some code you can show? Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273093 Share on other sites More sharing options...
deva Posted June 12, 2007 Author Share Posted June 12, 2007 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 Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273112 Share on other sites More sharing options...
Yesideez Posted June 12, 2007 Share Posted June 12, 2007 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: I suggest you check and make sure the paths and names of your PNG and TTF file are correct. Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273211 Share on other sites More sharing options...
deva Posted June 13, 2007 Author Share Posted June 13, 2007 thanks Yesideez.. the mistake was mine.. it was a problem of file permissions, which i solved and i get the result now.. Link to comment https://forums.phpfreaks.com/topic/55239-can-true-type-fonts-be-used-to-write-over-png-images/#findComment-273667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.