daveh33 Posted November 19, 2007 Share Posted November 19, 2007 I found this sample script online: - <?php if (empty($_SESSION['rand_code'])) { $str = ""; $length = 0; for ($i = 0; $i < 4; $i++) { // this numbers refer to numbers of the ascii table (small-caps) $str .= chr(rand(97, 122)); } $_SESSION['rand_code'] = $str; } $imgX = 60; $imgY = 20; $image = imagecreatetruecolor(60, 20); $backgr_col = imagecolorallocate($image, 238,239,239); $border_col = imagecolorallocate($image, 208,208,208); $text_col = imagecolorallocate($image, 46,60,31); imagefilledrectangle($image, 0, 0, 60, 20, $backgr_col); imagerectangle($image, 0, 0, 59, 19, $border_col); $font = "VeraSe.ttf"; // it's a Bitstream font check www.gnome.org for more $font_size = 10; $angle = 0; $box = imagettfbbox($font_size, $angle, $font, $_SESSION['rand_code']); $x = (int)($imgX - $box[4]) / 2; $y = (int)($imgY - $box[5]) / 2; imagettftext($image, $font_size, $angle, $x, $y, $text_col, $font, $_SESSION['rand_code']); header("Content-type: image/png"); imagepng($image); imagedestroy ($image); ?> Whatever I seem to do I cant seem to stop these errors Warning: imagettfbbox() [function.imagettfbbox]: Could not read font Warning: imagettftext() [function.imagettftext]: Could not read font Warning: Cannot modify header information - headers already sent by the font is in the same directory and the file is CMOD to 0777 Can someone please help and point out where I am going wrong Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/ Share on other sites More sharing options...
daveh33 Posted November 20, 2007 Author Share Posted November 20, 2007 Anyone have any ideas what would cause these errors? Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395062 Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 I have never worked with image function but from what I see in the errors it cannot find the font file "VeraSe.ttf" try some other font it may work Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395064 Share on other sites More sharing options...
daveh33 Posted November 20, 2007 Author Share Posted November 20, 2007 yes thats what I thought, is there a way to set it to arial or something default without having to specify the location of the font? Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395066 Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 try this $font = "fonts/arial.ttf"; Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395067 Share on other sites More sharing options...
daveh33 Posted November 20, 2007 Author Share Posted November 20, 2007 Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395079 Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2007 Share Posted November 20, 2007 just try $font = "arial.ttf"; Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395081 Share on other sites More sharing options...
daveh33 Posted November 20, 2007 Author Share Posted November 20, 2007 Still shows same error Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395084 Share on other sites More sharing options...
runnerjp Posted November 20, 2007 Share Posted November 20, 2007 try this...sometimes better to start from scratch <?php /* example of usage: inside your form <input type="text" name="validator" id="validator" size="4" /> <img src="random.php" alt="CAPTCHA image" width="60" height="20" vspace="1" align="top" /> and test the value of the "validator" form field like: if (!empty($_POST['validator']) && $_POST['validator'] == $_SESSION['rand_code']) { process your form here at least destroy the session unset($_SESSION['rand_code']); */ // save this code in your random script session_start(); if (empty($_SESSION['rand_code'])) { $str = ""; $length = 0; for ($i = 0; $i < 4; $i++) { // this numbers refer to numbers of the ascii table (small-caps) $str .= chr(rand(97, 122)); } $_SESSION['rand_code'] = $str; } $imgX = 60; $imgY = 20; $image = imagecreatetruecolor(60, 20); $backgr_col = imagecolorallocate($image, 238,239,239); $border_col = imagecolorallocate($image, 208,208,208); $text_col = imagecolorallocate($image, 46,60,31); imagefilledrectangle($image, 0, 0, 60, 20, $backgr_col); imagerectangle($image, 0, 0, 59, 19, $border_col); $font = "VeraSe.ttf"; // it's a Bitstream font check www.gnome.org for more $font_size = 10; $angle = 0; $box = imagettfbbox($font_size, $angle, $font, $_SESSION['rand_code']); $x = (int)($imgX - $box[4]) / 2; $y = (int)($imgY - $box[5]) / 2; imagettftext($image, $font_size, $angle, $x, $y, $text_col, $font, $_SESSION['rand_code']); header("Content-type: image/png"); imagepng($image); imagedestroy ($image); ?> Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395117 Share on other sites More sharing options...
daveh33 Posted November 20, 2007 Author Share Posted November 20, 2007 Tried that - here is the code I copied <?php /* example of usage: inside your form <input type="text" name="validator" id="validator" size="4" /> <img src="random.php" alt="CAPTCHA image" width="60" height="20" vspace="1" align="top" /> and test the value of the "validator" form field like: if (!empty($_POST['validator']) && $_POST['validator'] == $_SESSION['rand_code']) { process your form here at least destroy the session unset($_SESSION['rand_code']); */ // save this code in your random script session_start(); if (empty($_SESSION['rand_code'])) { $str = ""; $length = 0; for ($i = 0; $i < 4; $i++) { // this numbers refer to numbers of the ascii table (small-caps) $str .= chr(rand(97, 122)); } $_SESSION['rand_code'] = $str; } $imgX = 60; $imgY = 20; $image = imagecreatetruecolor(60, 20); $backgr_col = imagecolorallocate($image, 238,239,239); $border_col = imagecolorallocate($image, 208,208,208); $text_col = imagecolorallocate($image, 46,60,31); imagefilledrectangle($image, 0, 0, 60, 20, $backgr_col); imagerectangle($image, 0, 0, 59, 19, $border_col); $font = "VeraSe.ttf"; // it's a Bitstream font check www.gnome.org for more $font_size = 10; $angle = 0; $box = imagettfbbox($font_size, $angle, $font, $_SESSION['rand_code']); $x = (int)($imgX - $box[4]) / 2; $y = (int)($imgY - $box[5]) / 2; imagettftext($image, $font_size, $angle, $x, $y, $text_col, $font, $_SESSION['rand_code']); header("Content-type: image/png"); imagepng($image); imagedestroy ($image); ?> <input type="text" name="validator" id="validator" size="4" /> <img src="random.php" alt="CAPTCHA image" width="60" height="20" vspace="1" align="top" /> saved as random.php - it displays the below: - Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename Warning: imagettftext() [function.imagettftext]: Invalid font filename Warning: Cannot modify header information - headers already sent ‰PNG ��� IHDR���<������^aÉ~���GIDATxœíÎA �0ÀnAÇðï dØ£dIOÁˆÀoÀqŸn4Tæž>¼PšEi¥Y”fQšEi¥Y”f1�•9Ýè¹ÿÊ@x¸?´����IEND®B`‚ CAPTCHA image Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395140 Share on other sites More sharing options...
runnerjp Posted November 20, 2007 Share Posted November 20, 2007 humm thats intresting you are getting that same error as other script hummm gimme a bit to figure it out Link to comment https://forums.phpfreaks.com/topic/77998-random-image-code-validation-script/#findComment-395171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.