可能重复:
计算图像大小比例以调整大小
所以我有一个简单的上传脚本来调整上传图片的大小,我想强制宽度大小,让高度自动成比例。
这是我的上传脚本:
if (isset($_POST['upload'])) {
$dirupload = "../images/";
$dirupload = $dirupload . basename( $_FILES['image-upload']['name']);
$useless = $_POST['useless'];
$imageupload = ($_FILES['image-upload']['name']);
$uploadedfileupload = $_FILES['image-upload']['tmp_name'];
$uploadedfiletypeupload = $_FILES['image-upload']['type'];
$query_add="SELECT * FROM produits ORDER BY position";
$result_add=mysql_query($query_add);
$num_add=mysql_num_rows($result_add);
$add_add=$num_add+1;
if (!($uploadedfiletypeupload =="image/pjpeg" OR $uploadedfiletypeupload =="image/jpeg" OR $uploadedfiletypeupload =="image/jpg")){
echo "L'image doit être en .jpg ou .jpeg";
}else if (move_uploaded_file($_FILES['image-upload']['tmp_name'], $dirupload)){
$sql="INSERT INTO produits (position) VALUES ('$add_add')";
if (!mysql_query($sql,$con)){
die('Error: ' . mysql_error());
}
$newnameupload = "../images/produit" . mysql_insert_id() . ".jpg";
rename ("../images/$imageupload","$newnameupload");
$orig_imageupload = imagecreatefromjpeg("../image/$newnameupload");
$sm_imageupload = imagecreatetruecolor(274,219);
imagecopyresampled($sm_imageupload,$orig_imageupload,0,0,0,0,274,219,imagesx($orig_imageupload),imagesy($orig_imageupload));
imagejpeg($sm_imageupload, $newnameupload, 100);
}else{
echo "Un probleme est survenue";
}
}
关于试图让它发挥作用的任何想法?(是的,我现在确实在脚本中设置了高度)
提前致谢 !