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($img, 90, 0);
break;
case '180':
$img = imagerotate($img, 180, 0);
break;
case '270':
$img = imagerotate($img, 270, 0);
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($img, 180); // rotates it 180 clockwise
$img = rotate_image($img, 90, false); // rotates it 90 counter clockwise
header('Content-type: image/jpeg'); // set header
imagejpeg($img); // send image to browser
?>
0 Responses to rotate_image