我看过很多例子,但我不确定它如何与我目前拥有的上传脚本联系起来。有人可以解释一下我如何能够使用 ImageMagick 或类似的东西将上传的图像调整为固定宽度,同时保持 w:h 比率吗?
我用谷歌搜索并查看了 150 多个网页,但没有一个真正给出我认为适用于我的情况的示例。任何帮助,将不胜感激。这是我的代码:
// Include Extension finder function.
include_once 'find_extension.php';
// Function Gathers the Input Name, Store Number and Picture Number. The picture number is assigned by the loop that will be cycling through the images to be uploaded. The store Number and the Picure Number will make the file name.
function uploadImage($inputname, $storenum, $picturenum){
// A few parameters, to restrict file types and file size to 20kb.
if ((($_FILES[$inputname]["type"] == "image/gif")
|| ($_FILES[$inputname]["type"] == "image/png")
|| ($_FILES[$inputname]["type"] == "image/jpeg")
|| ($_FILES[$inputname]["type"] == "image/pjpeg"))
&& ($_FILES[$inputname]["size"] < 200000))
{
// If there is an error, echo the error, if not continue.
if ($_FILES[$inputname]["error"] > 0){
echo "Error: " . $_FILES[$inputname]["error"] . "<br />";
}else{
// Echo out File information.
/* echo "Upload: " . $_FILES[$inputname]["name"] . "<br />";
echo "Type: " . $_FILES[$inputname]["type"] . "<br />";
echo "Size: " . ($_FILES[$inputname]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES[$inputname]["tmp_name"]; */
}
// Get the extension so we can rename using the previous function.
$ext = findexts($_FILES[$inputname]["name"]);
$newpicturename = $storenum . $picturenum . "." . $ext;
// Check to see if the file exists, if it does then tell the user. If not continue.
if (file_exists("userimages/" . $newpicturename)){
echo "<br>" . $newpicturename . " already exists. ";
}else{
// Uploads the file.
move_uploaded_file($_FILES[$inputname]["tmp_name"], "userimages/" . $newpicturename);
$picturefield = "picture" . $picturenum;
$picturepath = "userimages/" . $newpicturename;
//Inserts data into ad DB
mysql_query("UPDATE storead SET $picturefield='$picturepath' WHERE storenum='$storenum'");
// Tells the User.
// echo "Stored in: " . "userimages/" . $newpicturename;
}
}else{
// If the upload does not meet the parameters above, then tell the user and cancel.
echo "Error uploading " . $_FILES[$inputname]["name"] . ". File may be too large or of unnacepted format.";
}
}
谢谢 :)