BigToach.com

PHP Snippets

image_inverse

Information

(PHP Version >= 4.0.6)
Functions used in this snippet: imagesx, imagesy, imagecreatetruecolor, imagecolorat, imagesetpixel, imagecolorallocate.

Description

int image_inverse( int img )

Makes the image img have all of its colors inversed.

*Note: This is a fairly slow function so it would be best to do it once and save the file for multiple viewings.

Snippet

<?php
function image_inverse($img){
    
$x imagesx($img);
    
$y imagesy($img);
    
$dest imagecreatetruecolor($x$y);
    for(
$i=0$i<$x$i++){
        for(
$j=0$j<$y$j++){
            
$rgb imagecolorat($img$i$j);
            
$r = ($rgb >> 16) & 0xFF;
            
$g = ($rgb >> 8) & 0xFF;
            
$b $rgb 0xFF;
            
imagesetpixel($dest$i$jimagecolorallocate($dest, (255 $r), (255 $g), (255 $b)));
        }
    }
    return 
$dest;
}
?>

Example

image_inverse Can be used in the following way:

<?php
$img 
imagecreatefromjpeg('someimage.jpg'); // create image

$img image_inverse($img); // inverses image

header('Content-type: image/jpeg'); // send header

imagejpeg($img); // output image to browser

?>

Added on Jul 6th at 8 pm by Scott - 0 Comments
Updated on Aug 3rd at 4 am.


0 Responses to image_inverse

Name:

Site or Mail:

Comment:

To try to reduce the ammount of spam, please enter the word GOOSE in the following form

Security Code: