有一种简单的方法可以在上传之前调整图像大小。一直在寻找一段时间,但似乎没有什么对我有用。我希望将所有内容调整为比例,只调整大小,如果有更大的东西,那么就说150.高度应该向下移动,以便图像看起来仍然应该如此。我有以下代码用于上传和重命名,但现在我想在此
之上实现调整大小$uploadDir = 'images/'; //Image Upload Folder
$fileName = $_FILES['file-0']['name'];
$tmpName = $_FILES['file-0']['tmp_name'];
$fileSize = $_FILES['file-0']['size'];
$fileType = $_FILES['file-0']['type'];
$temp = explode(".", $fileName);
$newfilename = $id . round(microtime(true)) . '.' . end($temp);
$result = move_uploaded_file($_FILES["file-0"]["tmp_name"], "images/" . $newfilename);
$filePath = $uploadDir . $newfilename;
if (!$result) {
echo "Error uploading file";
exit;
}
$query = "
update
pictures SET picture = '$filePath' Where
id = :id
";
$query_params = array(
':id' => $id
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch (PDOException $ex) {
die("Failed to run query: " . $ex->getMessage());
}
$row = $stmt->fetch();
答案 0 :(得分:1)
您可以使用以下地址的php类。我试过,它就像一个魅力。它可以动态调整图像大小。
http://www.bitrepository.com/resize-an-image-keeping-its-aspect-ratio-using-php-and-gd.html
您也可以查看下面的链接,了解一下: