<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>

            php生成高清縮略圖實例

            時間:2025-11-22 08:37:57 php語言

            php生成高清縮略圖實例

              php生成高清縮略圖的方法,較為詳細的分析了php生成縮略圖時出現失真的解決方法,并給出了完整實例進行總結分析,需要的朋友可以參考下。

              在使用php的函數生成縮略圖的使用,縮略圖很多情況下都會失真,這個時候需要有一些對應的解決方法。

              1.用imagecreatetruecolor和imageCopyreSampled函數分別取代imagecreate和imagecopyresized

              2.給imagejpeg的第三個參數帶上100(例:imagejpeg($ni,$toFile,100))

              下面是具體的函數

              function CreateSmallImage( $OldImagePath, $NewImagePath, $NewWidth=154, $NewHeight=134)

              {

              /pic/2jpg/3png),3(width="638" height="340")

              $OldImageInfo = getimagesize($OldImagePath);

              if ( $OldImageInfo[2] == 1 ) $OldImg = @imagecreatefromgif($OldImagePath);

              elseif ( $OldImageInfo[2] == 2 ) $OldImg = @imagecreatefromjpeg($OldImagePath);

              else $OldImg = @imagecreatefrompng($OldImagePath);

              /pic/p>

              $NewImg = imagecreatetruecolor( $NewWidth, $NewHeight );

              /pic/p>

              $black = ImageColorAllocate( $NewImg, 0, 0, 0 ); /pic/p>

              $white = ImageColorAllocate( $NewImg, 255, 255, 255 ); /pic/p>

              $red  = ImageColorAllocate( $NewImg, 255, 0, 0 ); /pic/p>

              $blue = ImageColorAllocate( $NewImg, 0, 0, 255 ); /pic/p>

              $other = ImageColorAllocate( $NewImg, 0, 255, 0 );

              /pic/p>

              $WriteNewWidth = $NewHeight*($OldImageInfo[0] / $OldImageInfo[1]); /pic/p>

              $WriteNewHeight = $NewWidth*($OldImageInfo[1] / $OldImageInfo[0]); /pic/p>

              /pic/p>

              if ($OldImageInfo[0] / $NewWidth > $org_info[1] / $NewHeight) {

              $WriteNewWidth = $NewWidth;

              $WriteNewHeight = $NewWidth / ($OldImageInfo[0] / $OldImageInfo[1]);

              } else {

              $WriteNewWidth = $NewHeight * ($OldImageInfo[0] / $OldImageInfo[1]);

              $WriteNewHeight = $NewHeight;

              }

              /pic/p>

              if ( $WriteNewWidth <= $NewWidth ) {

              $WriteNewWidth = $WriteNewWidth; /pic/p>

              $WriteNewHeight = $NewHeight; /pic/p>

              $WriteX = floor( ($NewWidth-$WriteNewWidth) / 2 ); /pic/p>

              $WriteY = 0;

              } else {

              $WriteNewWidth = $NewWidth; /pic/p>

              $WriteNewHeight = $WriteNewHeight; /pic/p>

              $WriteX = 0;

              $WriteY = floor( ($NewHeight-$WriteNewHeight) / 2 ); /pic/p>

              }

              /pic/p>

              @imageCopyreSampled( $NewImg, $OldImg, $WriteX, $WriteY, 0, 0, $WriteNewWidth, $WriteNewHeight, $OldImageInfo[0], $OldImageInfo[1] );

              /pic/p>

              /pic/p>

              @imagejpeg($NewImg, $NewImagePath, 100);

              /pic/p>

              @imagedestroy($NewImg);

              }

              CreateSmallImage("./images/jiexie.jpg","./images/jiexie.small.jpg",200,300);

              CreateSmallImage("./images/jiexie.jpg","./images/jiexie.middle.jpg",400,500);

              希望本文所述對大家php程序設計有所幫助。

            【php生成高清縮略圖實例】相關文章:

            PHP生成縮略圖的方法03-17

            php上傳圖片生成縮略圖02-17

            PHP生成縮略圖的類的方法10-14

            php生成圖片縮略圖的方法11-16

            php生成圖片縮略圖功能示例12-13

            PHP生成器簡單實例12-21

            PHP生成圖片縮略圖類示例代碼03-08

            php生成縮略圖的兩種方法02-12

            php生成sitemap.xml的實例代碼09-06

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看