Captcha Font

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
poepje
Forum Newbie
Posts: 6
Joined: Fri Sep 06, 2013 11:28 pm

Captcha Font

Post by poepje »

Hi,

the below code is my captcha i want to be able to set my own font how can i do this? and is it possible to turn this into a png image with transparancy background?

Code: Select all

<?php 
session_start(); 
//$text = rand(1000000,9999999); 
$text = rand(10000,99999); 
$_SESSION["vercode"] = $text; 

$height = 17; 
$width = 60; 
  
$image_p = imagecreate($width, $height); 
$black = imagecolorallocate($image_p,243,247,250); 
$white = imagecolorallocate($image_p, 0, 0, 0); 
$font_size = 8; 
  
imagestring($image_p, $font_size, 5, 0, $text, $white); 
imagejpeg($image_p, null,100); 

?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Captcha Font

Post by requinix »

For your own font, get a .ttf version of it and use imagettftext. For the transparency, use imagecolortransparent
Check the examples for ways to use them.
poepje
Forum Newbie
Posts: 6
Joined: Fri Sep 06, 2013 11:28 pm

Re: Captcha Font

Post by poepje »

thanks i will look into it i hope i can do it because i do not know anything about php
poepje
Forum Newbie
Posts: 6
Joined: Fri Sep 06, 2013 11:28 pm

Re: Captcha Font

Post by poepje »

tried some things but i don't get it, if someone can give me the good code of how it need to be, i have my own font "106beats.ttf" i don't know about php so probably impossible for me to fix it myself
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Captcha Font

Post by requinix »

What code do you have and what's not working?
poepje
Forum Newbie
Posts: 6
Joined: Fri Sep 06, 2013 11:28 pm

Re: Captcha Font

Post by poepje »

already deleted the faulty code. I'am not able to do this myself i do not know ANYTHING about php, is like speaking Chineese to me
poepje
Forum Newbie
Posts: 6
Joined: Fri Sep 06, 2013 11:28 pm

Re: Captcha Font

Post by poepje »

Code: Select all

<?php 
session_start(); 
//$text = rand(1000000,9999999); 
$text = rand(10000,99999); 
$_SESSION["vercode"] = $text; 

$height = 17; 
$width = 60; 
  
$image_p = imagecreate($width, $height); 
$black = imagecolorallocate($image_p,243,247,250); 
$white = imagecolorallocate($image_p, 0, 0, 0); 
$font_size = 8; 
$font = '106beats.ttf';
  
imagestring($image_p, $font_size, 5, 0, $text, $white, $font); 
imagejpeg($image_p, null,100); 

?>
captcha dissapears
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Captcha Font

Post by requinix »

Well you're not using imagettftext(), that's definitely a problem.

Try writing that code again and when (if) it doesn't work, don't delete the code but post it here so we can see what's wrong.
poepje
Forum Newbie
Posts: 6
Joined: Fri Sep 06, 2013 11:28 pm

Re: Captcha Font

Post by poepje »

try writing the code again, lol i can't write php, i do not know any php, this is not made by me that's why i came here trying to get it done
Post Reply