【发布时间】:2014-02-18 10:35:57
【问题描述】:
我有这个裁剪图像的脚本。如何保存到服务器?
move_uploaded_file($_FILES["file"]["tmp_name"],
"pictures/" . $_FILES["file"]["name"]);
$imgSrc = 'pictures/' . $_FILES["file"]["name"];
//getting the image dimensions
list($width, $height) = getimagesize($imgSrc);
//saving the image into memory (for manipulation with GD Library)
$myImage = imagecreatefromjpeg($imgSrc);
// calculating the part of the image to use for thumbnail
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
// copying the part into thumbnail
$thumbSize = 100;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
//final output
header('Content-type: image/jpeg');
imagejpeg($thumb);
如您所见,我能够输出图像。但是我无法保存它。在此先感谢:)
【问题讨论】:
-
我想在裁剪后保存任何类型的图像。所以基本上最后需要保存的是$thumb变量。