简体   繁体   English

在PHP中创建temporay拇指图像

[英]Creat temporay thumb image in PHP

Hey, i am looking for a method to creat temporay thumb file in PHP. 嘿,我正在寻找一种在PHP中创建temporay拇指文件的方法。 Is there any way not to store the image on the server or delete them right after. 有什么方法可以不将图像存储在服务器上或在之后将其删除。 What I am looking for is a solution like this: http://www.dig2go.com/index.php?shopbilde=772&type=1&size=120 我正在寻找的是这样的解决方案: http : //www.dig2go.com/index.php?shopbilde=772&type=1&size=120

Could some one explain to me how the php code behind this works? 可以给我解释一下背后的php代码如何工作吗? For the moment are am using a php code I found on the net for creation of thumb nails: 目前正在使用我在网上找到的用于创建指指甲的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;
    }
}

function createThumb($pathToImage, $pathToThumb, $thumbWidth, $thumbHeight, $saveNameAndPath) { if(!file_exists($pathToImage)) return false; 函数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;
    }
}

You can use ini_set("memory_limit","12M"); 您可以使用ini_set(“ memory_limit”,“ 12M”); to set memory limit in your script. 在脚本中设置内存限制。 You can extend it from 12 megabytes to maximum memory you have. 您可以将其从12 MB扩展到最大内存。

Generally 64M is good. 通常64M是好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM