Standard captcha - font size & color

Phoca Guestbook - creating guestbooks in Joomla! CMS
kr3ck3n
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 04 Aug 2012, 21:02

Standard captcha - font size & color

Post by kr3ck3n »

Hi!

I'm using phocaguestbook on my site and I have a little "design issue". This is the website i'm talking about and as you can see I've made some changes to the form and the last thing I want to do but I don't figure out how is to set up the captcha font (size, color, family).
I managed somehow to change the maximum number of displayed characters in the captcha image by modifying the code from /helpers/phocaguestbookcaptcha.php file (line 497, class PhocaguestbookHelperCaptcha} but I don't know how to setup the font...
What I want is a font written with Rockwell font-family ( I have the ttf file if needed ), the size must be around 22px and the color #676B61. Where can I add this values ?

PS: all I want is to have a similar captcha like this one.
PS2: the font-familly doesn't really matters, i'm more interest to solve the font-size and color.
Thanks!

LE: i've changed the font-color to #676B61, but I can't change the font-size now.. this is the website and I want to look like this
Last edited by kr3ck3n on 22 Aug 2012, 18:36, edited 1 time in total.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48742
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Standard captcha - font size & color

Post by Jan »

Hi, the captcha class needs to be customized but I don't have any experiences with the style on the second site, so cannot give any clue advice there :-(

Jan
If you find Phoca extensions useful, please support the project
kr3ck3n
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 04 Aug 2012, 21:02

Re: Standard captcha - font size & color

Post by kr3ck3n »

This is the code for the standard captcha:

Code: Select all

class PhocaguestbookHelperCaptcha
{
   function createImageData()
   {
      $rand_char           = PhocaguestbookHelperCaptcha::generateRandomChar(4);
      $rand_char_array     = array (         $rand_char[0]."          ",
                                 "  ".$rand_char[1]."        "   ,
                               "    ".$rand_char[2]."      "   ,
                              "      ".$rand_char[3]);

      $image_name       = PhocaguestbookHelperCaptcha::getRandomImage();
      $image             = @imagecreatefromjpeg($image_name);
      
      foreach ($rand_char_array as $key => $value)
      {
         $font_color    = PhocaguestbookHelperCaptcha::getRandomFontColor();
         $position_x    = mt_rand(5,8);
         $position_y    = mt_rand(6,9);
         $font_size       = mt_rand(4,5);
         
         ImageString($image, $font_size, $position_x, $position_y, $value, ImageColorAllocate ($image, $font_color[0], $font_color[1], $font_color[2]));
      }

      $image_data['outcome']       = $rand_char;
      $image_data['image']       = $image;
      
      return $image_data;
   }
   
   function generateRandomChar($length=4)
   {   
   
      $paramsC    = JComponentHelper::getParams('com_phocaguestbook') ;
      
      $charGroup = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z';
      if ($paramsC->get( 'standard_captcha_chars' ) != '') {
         $charGroup = str_replace(" ", "", trim( $paramsC->get( 'standard_captcha_chars' ) ));
      }
      $charGroup = explode( ',', $charGroup );
   
      
      srand ((double) microtime() * 1000000);
      
      $random_string = "";
      
      for($i=0;$i<$length;$i++)
      {
         $random_char_group = rand(0,sizeof($charGroup)-1);
         
         $random_string .= $charGroup[$random_char_group];
      }
      return $random_string;
   }

   function getRandomImage()
   {
      $rand = mt_rand(1,4);
      $image = '0'.$rand.'.jpg';
      $image = JPATH_ROOT.DS.'components'.DS.'com_phocaguestbook'.DS.'assets'.DS.'captcha'.DS . $image;
      return $image;
   }


   function getRandomFontColor()
   {
      $rand = mt_rand(1,6);
      if ($rand == 1) {$font_color[0] = 0; $font_color[1] = 0; $font_color[2] = 0;}
      if ($rand == 2) {$font_color[0] = 0; $font_color[1] = 0; $font_color[2] = 153;}
      if ($rand == 3) {$font_color[0] = 0; $font_color[1] = 102; $font_color[2] = 0;}
      if ($rand == 4) {$font_color[0] = 102; $font_color[1] = 51; $font_color[2] = 0;}
      if ($rand == 5) {$font_color[0] = 163; $font_color[1] = 0; $font_color[2] = 0;}
      if ($rand == 6) {$font_color[0] = 0; $font_color[1] = 82; $font_color[2] = 163;}
      return $font_color;
   }
}
I've removed the $rand_char[4] and $rand_char[5] from the function createImageData and that's how I managed to have 4 characters instead of 6 but the rest I don't know to modify.
Thanks!
kr3ck3n
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 04 Aug 2012, 21:02

Re: Standard captcha - font size & color

Post by kr3ck3n »

The captcha code is the following:

Code: Select all

class PhocaguestbookHelperCaptcha
{
function createImageData()
{
  $rand_char           = PhocaguestbookHelperCaptcha::generateRandomChar(4);
  $rand_char_array     = array (         $rand_char[0]."          ",
                             "  ".$rand_char[1]."        "   ,
                           "    ".$rand_char[2]."      "   ,
                          "      ".$rand_char[3]);

  $image_name       = PhocaguestbookHelperCaptcha::getRandomImage();
  $image             = @imagecreatefromjpeg($image_name);

  foreach ($rand_char_array as $key => $value)
  {
     $font_color    = PhocaguestbookHelperCaptcha::getRandomFontColor();
     $position_x    = mt_rand(5,8);
     $position_y    = mt_rand(6,9);
     $font_size       = mt_rand(4,5);

     ImageString($image, $font_size, $position_x, $position_y, $value, ImageColorAllocate ($image, $font_color[0], $font_color[1], $font_color[2]));
  }

  $image_data['outcome']       = $rand_char;
  $image_data['image']       = $image;

  return $image_data;
}

function generateRandomChar($length=4)
{   

  $paramsC    = JComponentHelper::getParams('com_phocaguestbook') ;

  $charGroup = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z';
  if ($paramsC->get( 'standard_captcha_chars' ) != '') {
     $charGroup = str_replace(" ", "", trim( $paramsC->get( 'standard_captcha_chars' ) ));
   }
  $charGroup = explode( ',', $charGroup );


  srand ((double) microtime() * 1000000);

  $random_string = "";

  for($i=0;$i<$length;$i++)
  {
     $random_char_group = rand(0,sizeof($charGroup)-1);

     $random_string .= $charGroup[$random_char_group];
  }
  return $random_string;
 }

  function getRandomImage()
{
  $rand = mt_rand(1,4);
  $image = '0'.$rand.'.jpg';
  $image = JPATH_ROOT.DS.'components'.DS.'com_phocaguestbook'.DS.'assets'.DS.'captcha'.DS . $image;
  return $image;
}


 function getRandomFontColor()
 {
  $rand = mt_rand(1,6);
  if ($rand == 1) {$font_color[0] = 0; $font_color[1] = 0; $font_color[2] = 0;}
  if ($rand == 2) {$font_color[0] = 0; $font_color[1] = 0; $font_color[2] = 153;}
  if ($rand == 3) {$font_color[0] = 0; $font_color[1] = 102; $font_color[2] = 0;}
  if ($rand == 4) {$font_color[0] = 102; $font_color[1] = 51; $font_color[2] = 0;}
  if ($rand == 5) {$font_color[0] = 163; $font_color[1] = 0; $font_color[2] = 0;}
  if ($rand == 6) {$font_color[0] = 0; $font_color[1] = 82; $font_color[2] = 163;}
  return $font_color;
  }
   }
I've removed the $rand_char[4] and $rand_char[5] from the function createImageData and that's how I managed to have 4 characters instead of 6.

COLOR - Solved! I changed this code:

Code: Select all

     function getRandomFontColor()
 {
  $rand = mt_rand(1,6);
  if ($rand == 1) {$font_color[0] = 0; $font_color[1] = 0; $font_color[2] = 0;}
  if ($rand == 2) {$font_color[0] = 0; $font_color[1] = 0; $font_color[2] = 153;}
  if ($rand == 3) {$font_color[0] = 0; $font_color[1] = 102; $font_color[2] = 0;}
  if ($rand == 4) {$font_color[0] = 102; $font_color[1] = 51; $font_color[2] = 0;}
  if ($rand == 5) {$font_color[0] = 163; $font_color[1] = 0; $font_color[2] = 0;}
  if ($rand == 6) {$font_color[0] = 0; $font_color[1] = 82; $font_color[2] = 163;}
  return $font_color;
  }
...to this one:

Code: Select all

     function getRandomFontColor()
 {
  $rand = mt_rand(1,1);
  if ($rand == 1) {$font_color[0] = 181; $font_color[1] = 181; $font_color[2] = 181;}
  return $font_color;
  }
So, the $font_color[0,1,2] where actualy the rgb code for the captcha color.

Now the only problem is with font-size. I've tried to add bigger values to this code: $font_size = mt_rand(4,5);, but no use...
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48742
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Standard captcha - font size & color

Post by Jan »

Hi, depends if it is TTF captcha (font can be resized) or not. In standard captcha the system font of the server is used (there are only 5 sizes for it and in Phoca Guestbook Captcha the largest is used)
If you find Phoca extensions useful, please support the project
kr3ck3n
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 04 Aug 2012, 21:02

Re: Standard captcha - font size & color

Post by kr3ck3n »

Thanks for your answer! It helped me.
I've changed the standard captcha to TTF Capctha and I've done all the changes I wanted and now it's ok.
The only inconvenient is that the space between letters is to big. Is there a way I can fix that?

Thanks!
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48742
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Standard captcha - font size & color

Post by Jan »

Hi, this is the same like with other changes, find the place where the space is defined and change it.
If you find Phoca extensions useful, please support the project
Post Reply