TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Tips & Tricks (http://www.talkphp.com/tips-tricks/)
-   -   Applying a Filter in GD (http://www.talkphp.com/tips-tricks/1897-applying-filter-gd.html)

Wildhoney 01-08-2008 01:33 PM

Applying a Filter in GD
 
In Rendair's thread about the wave effects for the reflections, somebody mentioned that you can apply overlay filters which affect the image below. So for example if I had a captcha image below, how could I apply a wave effect on the top to skew those letters?

What I'm trying to do is replicate the Gmail captcha image which is very simple, but merely skews the letters:


Orc 01-08-2008 01:56 PM

Could you give me an example of the Google Mail Captcha system?

Wildhoney 01-08-2008 01:58 PM

Can you not see the image in my original post? :-(

RobertK 01-08-2008 02:02 PM

I believe they use Imagick, not GD. The reason for this is the object has a direct "distortImage" method, and I cannot find a similar filter for GD. This is by best guess.

PHP: Imagick::distortImage - Manual

Orc 01-08-2008 02:03 PM

Quote:

Originally Posted by Wildhoney (Post 7912)
Can you not see the image in my original post? :-(


Sorry a bit tired.

Wildhoney 01-08-2008 02:25 PM

Thanks for your replies. So in that case, what is Kalle going on about in this post?

RobertK 01-08-2008 02:41 PM

I honestly have no clue, I'm not very experienced with GD. I do browse the manuals as I find questions though. From what I understand, as of PHP5, there's no predefined filter for waves or "wet floor"-like effects. imagefilter() is the function that applies a filter, but the defined constants don't include a wave filter.

Maybe they have a newer version?

Edit:

I think I found it, all the functions are hand made using the imagecopy() function. Some of the user contributed code is(authors bolded before the code):
administrador(ensaimada)sphoera(punt)com
PHP Code:

function wave_region($img$x$y$width$height,$grade=5){
        for (
$i=0;$i<$width;$i+=2){
            
imagecopy($img,$img,
                
$x+$i-2,$y+sin($i/10)*$grade,     //dest
                
$x+$i,$y,             //src
                
2,$height);
        }
    } 

designerkamal at gmail dot com
PHP Code:

function Skew($src$dest$skew_val)
{
  
$imgsrc imagecreatefromgif($src);
  
$width imagesx($imgsrc);
  
$height imagesy($imgsrc);
  
$imgdest imagecreatetruecolor($width$height+($height*$skew_val));
  
$trans imagecolorallocate($imgdest,0,0,0);
  
$temp=0;
  for(
$x=$x<$width $x++)
   {
     for(
$y=$y<$height $y++)
    {
        
imagecopy($imgdest$imgsrc$x$y+$temp$x$y11);
      
imagecolortransparent($imgdest,$trans);
       
    }
    
$temp+=$skew_val;
   }
  
imagepng($imgdest$dest);
  
imagedestroy($imgsrc);
  
imagedestroy($imgdest);


You could probably inspire some code for yourself based off these two functions, and get a slightly wavy skew filter.


All times are GMT. The time now is 12:13 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0