<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. PHP用GD庫生成高質量的縮略圖片

    時間:2025-12-12 21:32:10 php語言 我要投稿

    PHP用GD庫生成高質量的縮略圖片

      PHP用GD庫生成高質量的縮略圖片,PHP一般情況下生成的縮略圖都比較不理想。今天試用PHP,GD庫來生成縮略圖。雖然并不100%完美。可是也應該可以滿足縮略圖的要求了。

      以下是PHP源代碼(ResizeImage.php)。

      復制代碼 代碼如下:

      <?php

      $FILENAME="image.thumb";

      /pic/p>

      $RESIZEWIDTH=400;

      /pic/p>

      $RESIZEHEIGHT=400;

      function ResizeImage($im,$maxwidth,$maxheight,$name){

      $width = imagesx($im);

      $height = imagesy($im);

      if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){

      if($maxwidth && $width > $maxwidth){

      $widthratio = $maxwidth/$width;

      $RESIZEWIDTH=true;

      }

      if($maxheight && $height > $maxheight){

      $heightratio = $maxheight/$height;

      $RESIZEHEIGHT=true;

      }

      if($RESIZEWIDTH && $RESIZEHEIGHT){

      if($widthratio < $heightratio){

      $ratio = $widthratio;

      }else{

      $ratio = $heightratio;

      }

      }elseif($RESIZEWIDTH){

      $ratio = $widthratio;

      }elseif($RESIZEHEIGHT){

      $ratio = $heightratio;

      }

      $newwidth = $width * $ratio;

      $newheight = $height * $ratio;

      if(function_exists("imagecopyresampled")){

      $newim = imagecreatetruecolor($newwidth, $newheight);

      imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

      }else{

      $newim = imagecreate($newwidth, $newheight);

      imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

      }

      ImageJpeg ($newim,$name . ".jpg");

      ImageDestroy ($newim);

      }else{

      ImageJpeg ($im,$name . ".jpg");

      }

      }

      if($_FILES['image']['size']){

      if($_FILES['image']['type'] == "image/pjpeg"){

      $im = imagecreatefromjpeg($_FILES['image']['tmp_name']);

      }elseif($_FILES['image']['type'] == "image/x-png"){

      $im = imagecreatefrompng($_FILES['image']['tmp_name']);

      }elseif($_FILES['image']['type'] == "image/gif"){

      $im = imagecreatefromgif($_FILES['image']['tmp_name']);

      }

      if($im){

      if(file_exists("$FILENAME.jpg")){

      unlink("$FILENAME.jpg");

      }

      ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME);

      ImageDestroy ($im);

      }

      }

      ?>

      以下是測試代碼(demo.php)

      復制代碼 代碼如下:

      <?php

      include('ResizeImage.php');

      if(!empty($_POST)){

      echo($FILENAME.".jpg?cache=".rand(0,999999));

      }

      ?>

      <form name="test" action="?submit=true" enctype="multipart/form-data" method="post" >

      <input type="file" name="image" size="50" value="瀏覽"><p>

      <input type="submit" value="上傳圖片">

      </form>

    【PHP用GD庫生成高質量的縮略圖片】相關文章:

    php生成圖片縮略圖的方法07-25

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

    php生成圖片縮略圖功能示例10-31

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

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

    PHP生成縮略圖的類的方法08-05

    php生成高清縮略圖實例02-05

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

    php生成圓角圖片的方法技巧10-02

    • 相關推薦
    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人