| AND OR | string words | *

image editing

|

image rotate


function to rotate an image.


function rotatePix( ) [ line 2 ]



full source of image rotate [ line 1 - 40 ] | download image rotate

1    <?    
2   function rotatePix($sourcefile$targetfile$degrees)
3   {
4       $img_size getImageSize($sourcefile);
5       $x $img_size[0];
6       $y $img_size[1];
7       if ($x $y)
8       {
9               $dst_x 0;
10               $dst_y $x $y;
11               $newd $x;
12       }
13       else
14       {
15               $dst_x $y $x;
16               $dst_y 0;
17               $newd $y;
18       }
19       $src_img ImageCreateFromJPEG($sourcefile);
20       $dst_img ImageCreateTrueColor($newd,$newd);
21       if ((($x y) && ($degrees 180)) || (($y $x) && ($degrees 180)))
22               ImageCopyResampled($dst_img,$src_img,0,0,0,0,$x,$y,$x,$y);
23       else
24               ImageCopyResampled($dst_img,$src_img,$dst_x,$dst_y,0,0,$x,$y,$x,$y);
25       $rotated_img ImageRotate($dst_img$degrees,0);
26       if ($degrees != 180)
27       {
28               //90 CounterClockWise or Clockwise
29               $final_img ImageCreateTrueColor($y,$x);
30               ImageCopyResampled($final_img,$rotated_img,0,0,0,0,$y,$x,$y,$x);
31       }
32       else
33       {
34               //180 Degrees
35               $final_img ImageCreateTrueColor($x,$y);
36               ImageCopyResampled($final_img,$rotated_img,0,0,0,0,$x,$y,$x,$y);
37       }
38       ImageJPEG($final_img$targetfile);     
39   }
40   ?>



37 hits by 17 users in the last 30 minutes.