0

ねえ、私はPHPでtemporayサムファイルを作成する方法を探しています。サーバーに画像を保存したり、すぐに削除したりしない方法はありますか?私が探しているのは、次のようなソリューションです。http

://www.dig2go.com/index.php?shopbilde=772&type=1&size= 120この背後にあるphpコードがどのように機能するかを誰かに説明してもらえますか?今のところ、サムネイルの作成にネット上で見つけたphpコードを使用しています。

function createThumb($pathToImage, $pathToThumb, $thumbWidth, $thumbHeight,    $saveNameAndPath)
{
   if(!file_exists($pathToImage))
   return false;

   else
   {
      //Load image and size
      $img = imagecreatefromjpeg($pathToImage);
      $width = imagesx($img);
      $height = imagesy($img);

      //Calculate the size of thumb
      $new_width = $thumbWidth;
      $new_height = $thumbHeight; //floor($height * ($thumbWidth / $width));

      //Make the new thumb
      $tmp_img = imagecreatetruecolor($new_width, $new_height);

      //Copy the old image and calculate the size
      imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

      //Save the thumb to jpg 
      imagejpeg($tmp_img, $saveNameAndPath);

      return true;
    }
}
4

2 に答える 2

1

function createThumb($ pathToImage、$ pathToThumb、$ thumbWidth、$ thumbHeight、$ saveNameAndPath){if(!file_exists($ pathToImage))はfalseを返します;

   else
   {
      //Load image and size
      $img = imagecreatefromjpeg($pathToImage);
      $width = imagesx($img);
      $height = imagesy($img);

      //Calculate the size of thumb
      $new_width = $thumbWidth;
      $new_height = $thumbHeight; //floor($height * ($thumbWidth / $width));

      //Make the new thumb
      $tmp_img = imagecreatetruecolor($new_width, $new_height);

      //Copy the old image and calculate the size
      imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
      // sets the header and creates the temporary thumbnail
      // ideal for ajax requests / <img> elements
      header("Content-type: image/jpeg");
      imagejpeg($img);

      return true;
    }
}
于 2009-09-06T17:01:15.307 に答える
1

ini_set( "memory_limit"、 "12M");を使用できます。スクリプトにメモリ制限を設定します。12メガバイトから最大メモリまで拡張できます。

一般的に64Mが良いです。

于 2013-12-11T12:22:26.087 に答える