• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/modules/form/captcha/class/filter.class.php

Go to the documentation of this file.
00001 <?php
00002 
00003   /******************************************************************
00004 
00005    Projectname:   CAPTCHA class
00006    Version:       2.0
00007    Author:        Pascal Rehfeldt <Pascal@Pascal-Rehfeldt.com>
00008    Last modified: 15. January 2006
00009 
00010    * GNU General Public License (Version 2, June 1991)
00011    *
00012    * This program is free software; you can redistribute
00013    * it and/or modify it under the terms of the GNU
00014    * General Public License as published by the Free
00015    * Software Foundation; either version 2 of the License,
00016    * or (at your option) any later version.
00017    *
00018    * This program is distributed in the hope that it will
00019    * be useful, but WITHOUT ANY WARRANTY; without even the
00020    * implied warranty of MERCHANTABILITY or FITNESS FOR A
00021    * PARTICULAR PURPOSE. See the GNU General Public License
00022    * for more details.
00023 
00024    Description:
00025    Filters
00026 
00027   ******************************************************************/
00028 
00029   class filters
00030   {
00031         
00032     function noise (&$image, $runs = 30)
00033     {
00034         
00035           $w = imagesx($image);
00036           $h = imagesy($image);
00037   
00038       for ($n = 0; $n < $runs; $n++)
00039       {
00040 
00041         for ($i = 1; $i <= $h; $i++)
00042         {
00043 
00044           $randcolor = imagecolorallocate($image,
00045                                           mt_rand(0, 255),
00046                                           mt_rand(0, 255),
00047                                           mt_rand(0, 255));
00048 
00049           imagesetpixel($image,
00050                         mt_rand(1, $w),
00051                         mt_rand(1, $h),
00052                         $randcolor);
00053 
00054         }
00055 
00056       }  
00057   
00058     } //noise
00059     
00060     function signs (&$image, $font, $cells = 3)
00061     {
00062         
00063           $w = imagesx($image);
00064           $h = imagesy($image);
00065 
00066           for ($i = 0; $i < $cells; $i++)
00067           {
00068                                 
00069                 $centerX     = mt_rand(1, $w);
00070                 $centerY     = mt_rand(1, $h);
00071                 $amount      = mt_rand(1, 15);
00072         $stringcolor = imagecolorallocate($image, 175, 175, 175);
00073                 
00074                 for ($n = 0; $n < $amount; $n++)
00075                 {
00076 
00077           $signs = range('A', 'Z');
00078           $sign  = $signs[mt_rand(0, count($signs) - 1)];
00079 
00080                   imagettftext($image, 25, 
00081                                mt_rand(-15, 15), 
00082                                $centerX + mt_rand(-50, 50),
00083                                $centerY + mt_rand(-50, 50),
00084                                $stringcolor, $font, $sign);
00085                 
00086                 }
00087                 
00088           }
00089         
00090     } //signs
00091     
00092     function blur (&$image, $radius = 3)
00093     {
00094 
00095           $radius  = round(max(0, min($radius, 50)) * 2);
00096 
00097           $w       = imagesx($image);
00098           $h       = imagesy($image);
00099           
00100           $imgBlur = imagecreate($w, $h);
00101 
00102           for ($i = 0; $i < $radius; $i++)
00103           {
00104 
00105                 imagecopy     ($imgBlur, $image,   0, 0, 1, 1, $w - 1, $h - 1);
00106                 imagecopymerge($imgBlur, $image,   1, 1, 0, 0, $w,     $h,     50.0000);
00107                 imagecopymerge($imgBlur, $image,   0, 1, 1, 0, $w - 1, $h,     33.3333);
00108                 imagecopymerge($imgBlur, $image,   1, 0, 0, 1, $w,     $h - 1, 25.0000);
00109                 imagecopymerge($imgBlur, $image,   0, 0, 1, 0, $w - 1, $h,     33.3333);
00110                 imagecopymerge($imgBlur, $image,   1, 0, 0, 0, $w,     $h,     25.0000);
00111                 imagecopymerge($imgBlur, $image,   0, 0, 0, 1, $w,     $h - 1, 20.0000);
00112                 imagecopymerge($imgBlur, $image,   0, 1, 0, 0, $w,     $h,     16.6667);
00113                 imagecopymerge($imgBlur, $image,   0, 0, 0, 0, $w,     $h,     50.0000);
00114                 imagecopy     ($image  , $imgBlur, 0, 0, 0, 0, $w,     $h);
00115 
00116           }
00117           
00118           imagedestroy($imgBlur);
00119           
00120     } //blur
00121 
00122   } //class: filters
00123 

Generated on Sun Jan 2 2011 04:55:32 for Pragyan CMS by  doxygen 1.7.1