Home > php教程 > php手册 > PHP图像操作:3D图、缩放、旋转、裁剪、添加水印(三)

PHP图像操作:3D图、缩放、旋转、裁剪、添加水印(三)

WBOY
Release: 2016-06-13 09:24:24
Original
1294 people have browsed it

PHP图像操作:3D图、缩放、旋转、裁剪、添加水印(三)

来源:http://www.ido321.com/887.html

5、PHP对图像的旋转

   1: <p>
Copy after login
   2:     <h4>旋转之前</h4>
Copy after login
   3:     
Copy after login
   4: </p>
Copy after login
   5: <?php
Copy after login
   6: header("content-type","text/html;charset=utf-8");
Copy after login
   7:  
Copy after login
   8: /*
Copy after login
   9: *图片沿y轴旋转,以png&#26684;式为例
Copy after login
  10: *@param string $filename 图片的url
Copy after login
  11: */
Copy after login
  12: function turn_y($filename)
Copy after login
  13: {
Copy after login
  14:     /*创建图片资源*/
Copy after login
  15:     $backy = imagecreatefrompng($filename);
Copy after login
  16:  
Copy after login
  17:     /*获取大小*/
Copy after login
  18:     $widthy = imagesx($backy);
Copy after login
  19:     $heighty = imagesy($backy);
Copy after login
  20:  
Copy after login
  21:     /*创建新的图片资源,保存翻转后的图片*/
Copy after login
  22:     $newy = imagecreatetruecolor($widthy, $heighty);
Copy after login
  23:  
Copy after login
  24:     /*沿着y轴翻转,就是将原图从右向左按一个像素宽度向新资源中逐个复制*/
Copy after login
  25:     for ($i=0; $i < $widthy; $i&#43;&#43;) { 
Copy after login
  26:         imagecopy($newy,$backy,$widthy-$i-1,0,$i,0,1,$heighty);
Copy after login
  27:     }
Copy after login
  28:  
Copy after login
  29:     /*保存翻转后的图片*/
Copy after login
  30:     imagepng($newy,'http://www.bkjia.com/uploads/allimg/141009/0425435558-1.png');
Copy after login
  31:  
Copy after login
  32:     /*释放资源*/
Copy after login
  33:     imagedestroy($backy);
Copy after login
  34:     imagedestroy($newy);
Copy after login
  35: }
Copy after login
  36:  
Copy after login
  37: /*
Copy after login
  38: *图片沿x轴旋转,以png&#26684;式为例
Copy after login
  39: *@param string $filename 图片的url
Copy after login
  40: */
Copy after login
  41: function turn_x($filename)
Copy after login
  42: {
Copy after login
  43:     /*创建图片资源*/
Copy after login
  44:     $backx = imagecreatefrompng($filename);
Copy after login
  45:  
Copy after login
  46:     /*获取大小*/
Copy after login
  47:     $widthx = imagesx($backx);
Copy after login
  48:     $heightx = imagesy($backx);
Copy after login
  49:  
Copy after login
  50:     /*创建新的图片资源,保存翻转后的图片*/
Copy after login
  51:     $newx = imagecreatetruecolor($widthx, $heightx);
Copy after login
  52:  
Copy after login
  53:     /*沿着x轴翻转,就是将原图从上到下按一个像素宽度向新资源中逐个复制*/
Copy after login
  54:     for ($i=0; $i < $heightx; $i&#43;&#43;) { 
Copy after login
  55:         imagecopy($newx,$backx,0,$heightx-$i-1,0,$i,$widthx,1);
Copy after login
  56:     }
Copy after login
  57:  
Copy after login
  58:     /*保存翻转后的图片*/
Copy after login
  59:     imagepng($newx,'http://www.bkjia.com/uploads/allimg/141009/0425432228-2.png');
Copy after login
  60:  
Copy after login
  61:     /*释放资源*/
Copy after login
  62:     imagedestroy($backx);
Copy after login
  63:     imagedestroy($newx);
Copy after login
  64: }
Copy after login
  65: /*调用函数*/
Copy after login
  66: turn_y('http://www.bkjia.com/uploads/allimg/141009/0425435O8-0.png');
Copy after login
  67: turn_x('http://www.bkjia.com/uploads/allimg/141009/0425435O8-0.png');
Copy after login
  68: ?>
Copy after login
  69: <p style="float:left">
Copy after login
  70:     <h4>沿着y轴旋转</h4>
Copy after login
  71:     
Copy after login
  72: </p>
Copy after login
  73: <p style="float:left">
Copy after login
  74:     <h4>沿着x轴旋转</h4>
Copy after login
  75:     
Copy after login
  76: </p>
Copy after login

效果


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template