【发布时间】:2013-12-11 20:22:26
【问题描述】:
嘿,我正在寻找一种在 PHP 中创建临时拇指文件的方法。有没有办法不将图像存储在服务器上或立即删除它们。我正在寻找的是这样的解决方案: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;
}
}
【问题讨论】:
-
我知道这是旧的。只是想知道答案是否好。加上一些使用提示。欢呼
-
它实际上非常有帮助,我记得它让它起作用了。但是我使用的代码我不知道去哪里了。你有什么问题? :)
标签: php thumbnails temporary-files