TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-26-2008, 01:11 PM   #1 (permalink)
The Addict
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 247
Thanks: 6
Kalle is on a distinguished road
Default Simple pixelate + negative functions

So over the last few months I've developed a few helper functions for some image related stuff I've been working on using PHP and GD and thought I would share them...

The filters simply introduces a function to pixelate an image resource and the second one makes all colors negative just like the imagefilter($im, IMG_FILTER_NEGATE) function, however since this is written in PHP theres really a difference in using my version and the C version, so use that if possible.

Sources:
PHP Code:
<?php
    
function imagepixelate($im$blocksize)
    {
        
$blocksize = (int) $blocksize;

        if(
$blocksize 0)
        {
            return(
false);
        }

        if(
$blocksize == 1)
        {
            return(
true);
        }

        for(
$x 0$x imagesx($im); $x += $blocksize)
        {
            for(
$y 0$y imagesy($im); $y += $blocksize)
            {
                if(!@
ImageFilledRectangle($im$x$y, ($x $blocksize 1), ($y $blocksize -1), ImageColorAt($im$x$y)))
                {
                    return(
false);
                }
            }
        }

        return(
true);
    }

    function 
imagenegate($im)
    {
        for(
$x 0$x imagesx($im); ++$x)
        {
            for(
$y 0$y imagesy($im); ++$y)
            {
                
$rgb imagecolorat($im$x$y);

                
imagesetpixel($im$x$yimagecolorallocate($im, (255 - (($rgb >> 16) & 0xFF)), (255 - (($rgb >> 8) & 0xFF)), (255 -($rgb 0xFF))));
            }
        }

        return(
true);
    }
?>
Note that I removed my checks for valid resource streams as these were apart of a smaller framework/package, so be sure to pass a valid image stream to them.


Prototypes:
bool imagepixelate( resource $im, integer $blocksize )
Pixelates an image

$im - A valid resource to a GD image
$blocksize - How many pixels that should go on each block, 1 = no effect because 1 = 1 pixel


bool imagenegate( resource $im )
Reverses color and creates a negative effect

$im - A valid resource to a GD image



Cheers, hope this will help someone ;)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
The Following User Says Thank You to Kalle For This Useful Post:
ETbyrne (07-27-2008)
Old 07-27-2008, 03:49 AM   #2 (permalink)
The Acquainted
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 181
Thanks: 34
ETbyrne is on a distinguished road
Default

Cool! I've got to check this out right now!
__________________
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:50 PM.

 
     

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