欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實(shí)現(xiàn)圖片旋轉(zhuǎn)效果實(shí)例代碼

 更新時間:2014年10月01日 15:27:34   投稿:junjie  
這篇文章主要介紹了PHP實(shí)現(xiàn)圖片旋轉(zhuǎn)效果實(shí)例代碼,本文給出代碼示例,代碼中包含一些說明注釋,需要的朋友可以參考下

PHP對圖像的旋轉(zhuǎn)

<div>
    <h4>旋轉(zhuǎn)之前</h4>
    <img src="1.png" style="border:1px solid red;">
  </div>
  <?php
  header("content-type","text/html;charset=utf-8");
   
  /*
  *圖片沿y軸旋轉(zhuǎn),以png格式為例
  *@param string $filename 圖片的url
  */
  function turn_y($filename)
  {
    /*創(chuàng)建圖片資源*/
    $backy = imagecreatefrompng($filename);
  
    /*獲取大小*/
    $widthy = imagesx($backy);
    $heighty = imagesy($backy);
  
    /*創(chuàng)建新的圖片資源,保存翻轉(zhuǎn)后的圖片*/
    $newy = imagecreatetruecolor($widthy, $heighty);
  
    /*沿著y軸翻轉(zhuǎn),就是將原圖從右向左按一個像素寬度向新資源中逐個復(fù)制*/
    for ($i=0; $i < $widthy; $i++) { 
      imagecopy($newy,$backy,$widthy-$i-1,0,$i,0,1,$heighty);
    }
  
    /*保存翻轉(zhuǎn)后的圖片*/
    imagepng($newy,'test3.png');
  
    /*釋放資源*/
    imagedestroy($backy);
    imagedestroy($newy);
  }
  
  /*
  *圖片沿x軸旋轉(zhuǎn),以png格式為例
  *@param string $filename 圖片的url
  */
  function turn_x($filename)
  {
    /*創(chuàng)建圖片資源*/
    $backx = imagecreatefrompng($filename);
  
    /*獲取大小*/
    $widthx = imagesx($backx);
    $heightx = imagesy($backx);
  
    /*創(chuàng)建新的圖片資源,保存翻轉(zhuǎn)后的圖片*/
    $newx = imagecreatetruecolor($widthx, $heightx);
  
    /*沿著x軸翻轉(zhuǎn),就是將原圖從上到下按一個像素寬度向新資源中逐個復(fù)制*/
    for ($i=0; $i < $heightx; $i++) { 
      imagecopy($newx,$backx,0,$heightx-$i-1,0,$i,$widthx,1);
    }
  
    /*保存翻轉(zhuǎn)后的圖片*/
    imagepng($newx,'test4.png');
  
    /*釋放資源*/
    imagedestroy($backx);
    imagedestroy($newx);
  }
  /*調(diào)用函數(shù)*/
  turn_y('1.png');
  turn_x('1.png');
  ?>
  <div style="float:left">
    <h4>沿著y軸旋轉(zhuǎn)</h4>
    <img src="test3.png" style="border:1px solid red;">
  </div>
  <div style="float:left">
    <h4>沿著x軸旋轉(zhuǎn)</h4>
    <img src="test4.png" style="border:1px solid red;">
  </div>

相關(guān)文章

最新評論