[英]Creat temporay thumb image in PHP
嘿,我正在寻找一种在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;
}
}
函数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;
}
}
您可以使用ini_set(“ memory_limit”,“ 12M”); 在脚本中设置内存限制。 您可以将其从12 MB扩展到最大内存。
通常64M是好的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.