communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "image editing" - download "image rotate"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

image editing - image rotate was created/last modified on Mon 06 Oct 2003 7:08 PM

<?    
     
function rotatePix($sourcefile, $targetfile, $degrees)
     {
         
$img_size = getImageSize($sourcefile);
         
$x = $img_size[0];
         
$y = $img_size[1];
         if (
$x > $y)
         {
                 
$dst_x = 0;
                 
$dst_y = $x - $y;
                 
$newd = $x;
         }
         else
         {
                 
$dst_x = $y - $x;
                 
$dst_y = 0;
                 
$newd = $y;
         }
         
$src_img = ImageCreateFromJPEG($sourcefile);
         
$dst_img = ImageCreateTrueColor($newd,$newd);
         
         if (((
$x > y) && ($degrees < 180)) || (($y > $x) && ($degrees > 180)))
                 
ImageCopyResampled($dst_img,$src_img,0,0,0,0,$x,$y,$x,$y);
         else
                 
ImageCopyResampled($dst_img,$src_img,$dst_x,$dst_y,0,0,$x,$y,$x,$y);
         
         
$rotated_img = ImageRotate($dst_img, $degrees,0);
         
         if (
$degrees != 180)
         {
                 
//90 CounterClockWise or Clockwise
                 
$final_img = ImageCreateTrueColor($y,$x);
                 
ImageCopyResampled($final_img,$rotated_img,0,0,0,0,$y,$x,$y,$x);
         }
         else
         {
                 
//180 Degrees
                 
$final_img = ImageCreateTrueColor($x,$y);
                 
ImageCopyResampled($final_img,$rotated_img,0,0,0,0,$x,$y,$x,$y);
         }
         
ImageJPEG($final_img, $targetfile);     
     }
?>

learn more about some of the PHP functions used in this snippet: else, file, function, rotate

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari