BigToach.com

PHP Snippets

image_flip

Information

(PHP Version >= 4.0.6)
Functions used in this snippet: imagesx, imagesy, imagecreatetruecolor, imagecopy, imagedestroy.

Description

int image_flip( int img[, str type] )

Flips the image img to the direction of type

Snippet

<?php
function image_flip($img$type=''){
    
$width  imagesx($img);
    
$height imagesy($img);
    
$dest   imagecreatetruecolor($width$height);
    switch(
$type){
        case 
'':
            return 
$img;
        break;
        case 
'vert':
            for(
$i=0;$i<$height;$i++){
                
imagecopy($dest$img0, ($height $i 1), 0$i$width1);
            }
        break;
        case 
'horiz':
            for(
$i=0;$i<$width;$i++){
                
imagecopy($dest$img, ($width $i 1), 0$i01$height);
            }
        break;
        case 
'both':
            for(
$i=0;$i<$width;$i++){
                
imagecopy($dest$img, ($width $i 1), 0$i01$height);
            
            }
            
$buffer imagecreatetruecolor($width1);
            for(
$i=0;$i<($height/2);$i++){
                
imagecopy($buffer$dest000, ($height $i -1), $width1);
                
imagecopy($dest$dest0, ($height $i 1), 0$i$width1);
                
imagecopy($dest$buffer0$i00$width1);
            }
            
imagedestroy($buffer);
        break;
    }
    return 
$dest;
}
?>

Example

image_flip Can be used in the following way:

<?php
$img 
imagecreatefromjpeg('somefile.jpg'); // create an image
$img image_flip($img'vert'); // flips image vertically

$img image_flip($img'horiz'); // flips image horizontally

$img image_flip($img'both'); // flips image both ways

header('Content-type: image/jpeg'); // send header
imagejpeg($img); // send image to browser
?>

Added on Jul 6th at 5 am by Scott - 0 Comments


0 Responses to image_flip

Name:

Site or Mail:

Comment:

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

Security Code: