对图片进行翻转

 1 <?php
 2     function turn_y($filename){
 3         $image_back = imagecreatefromjpeg($filename);
 4         
 5         $width = imagesx($image_back);
 6         $height = imagesy($image_back);
 7         
 8         $image_new = imagecreatetruecolor($width,$height);
 9         
10         for($x = 0;$x < $width;$x ++){
11             imagecopy($image_new,$image_back,$width - $x - 1,0,$x,0,1,$height);
12         }
13         
14         imagejpeg($image_new,$filename);
15         
16         imagedestroy($image_back);
17         imagedestroy($image_new);
18     }
19     
20     function turn_x($filename){
21         $image_back = imagecreatefromjpeg($filename);
22         
23         $width = imagesx($image_back);
24         $height = imagesy($image_back);
25         
26         $image_new = imagecreatetruecolor($width,$height);
27         
28         for($y = 0;$y < $height;$y ++){
29             imagecopy($image_new,$image_back,0,$height - $y - 1,0,$y,$width,1);
30         }
31         
32         imagejpeg($image_new,$filename);
33         
34         imagedestroy($image_back);
35         imagedestroy($image_new);
36     }
37     
38     turn_x("mm2.jpeg");
39 ?>
turn_y turn_x

 

posted @ 2015-11-24 12:58  banshaohuan  阅读(270)  评论(0编辑  收藏  举报