BigToach.com

PHP Snippets

rotate_image

Information

(PHP Version >= 3)
Functions used in this snippet: imagerotate.

Description

int rotate_image( int img[, int degrees[, bool cw]] )

Uses the image img and rotates it according to degrees clockwise. If cw is set to false the function rotates the images in a counter clockwise motion.

Snippet

<?php
function rotate_image($img$degrees='90'$cw=true){
    
$degrees $cw $degrees : (360 $degrees);
    switch(
$degrees){
        case 
'90':
            
$img imagerotate($img900);
        break;
        case 
'180':
            
$img imagerotate($img1800);
        break;
        case 
'270':
            
$img imagerotate($img2700);
        break;
    }
    return 
$img;
}
?>

Example

rotate_image Can be used in the following way:

<?php
$img 
imagecreatefromjpeg('somefile.jpg'); // load image

$img rorate_image($img); // rotates it 90 clockwise

$img rotate_image($img180); // rotates it 180 clockwise

$img rotate_image($img90false); // rotates it 90 counter clockwise

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

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

?>

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


0 Responses to rotate_image

Name:

Site or Mail:

Comment:

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

Security Code: