PHP映像操作:3D圖、縮放、旋轉、裁剪、添加浮水印(三)_PHP教程

來源:互聯網
上載者:User

PHP映像操作:3D圖、縮放、旋轉、裁剪、添加浮水印(三)


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

5、PHP對映像的旋轉

   1: 
   2:     

旋轉之前

   3:     
   4: 
   5: 
   6: header("content-type","text/html;charset=utf-8");
   7:  
   8: /*
   9: *圖片沿y軸旋轉,以png格式為例
  10: *@param string $filename 圖片的url
  11: */
  12: function turn_y($filename)
  13: {
  14:     /*建立圖片資源*/
  15:     $backy = imagecreatefrompng($filename);
  16:  
  17:     /*擷取大小*/
  18:     $widthy = imagesx($backy);
  19:     $heighty = imagesy($backy);
  20:  
  21:     /*建立新的圖片資源,儲存翻轉後的圖片*/
  22:     $newy = imagecreatetruecolor($widthy, $heighty);
  23:  
  24:     /*沿著y軸翻轉,就是將原圖從右向左按一個像素寬度向新資源中逐個複製*/
  25:     for ($i=0; $i < $widthy; $i++) { 
  26:         imagecopy($newy,$backy,$widthy-$i-1,0,$i,0,1,$heighty);
  27:     }
  28:  
  29:     /*儲存翻轉後的圖片*/
  30:     imagepng($newy,'http://www.bkjia.com/uploads/allimg/141009/0425435558-1.png');
  31:  
  32:     /*釋放資源*/
  33:     imagedestroy($backy);
  34:     imagedestroy($newy);
  35: }
  36:  
  37: /*
  38: *圖片沿x軸旋轉,以png格式為例
  39: *@param string $filename 圖片的url
  40: */
  41: function turn_x($filename)
  42: {
  43:     /*建立圖片資源*/
  44:     $backx = imagecreatefrompng($filename);
  45:  
  46:     /*擷取大小*/
  47:     $widthx = imagesx($backx);
  48:     $heightx = imagesy($backx);
  49:  
  50:     /*建立新的圖片資源,儲存翻轉後的圖片*/
  51:     $newx = imagecreatetruecolor($widthx, $heightx);
  52:  
  53:     /*沿著x軸翻轉,就是將原圖從上到下按一個像素寬度向新資源中逐個複製*/
  54:     for ($i=0; $i < $heightx; $i++) { 
  55:         imagecopy($newx,$backx,0,$heightx-$i-1,0,$i,$widthx,1);
  56:     }
  57:  
  58:     /*儲存翻轉後的圖片*/
  59:     imagepng($newx,'http://www.bkjia.com/uploads/allimg/141009/0425432228-2.png');
  60:  
  61:     /*釋放資源*/
  62:     imagedestroy($backx);
  63:     imagedestroy($newx);
  64: }
  65: /*調用函數*/
  66: turn_y('http://www.bkjia.com/uploads/allimg/141009/0425435O8-0.png');
  67: turn_x('http://www.bkjia.com/uploads/allimg/141009/0425435O8-0.png');
  68: ?>
  69: 
  70:     

沿著y軸旋轉

  71:     
  72: 
  73: 
  74:     

沿著x軸旋轉

  75:     
  76: 

效果


http://www.bkjia.com/PHPjc/890204.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/890204.htmlTechArticlePHP映像操作:3D圖、縮放、旋轉、裁剪、添加浮水印(三) 來源:http://www.ido321.com/887.html 5、PHP對映像的旋轉 1: 2: 旋轉之前 3: 4: 5: 6: header("...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.