0
我想這樣做,如果圖像超過尺寸604x453,然後調整它的大小爲604x453。PHP:if more than ..px resize to
香港專業教育學院做了這麼遠:
$org_name = stripslashes($_FILES[$upload_name]['name']);
$file_size = $_FILES[$upload_name]['size'];
$file_temp = $_FILES[$upload_name]['tmp_name'];
$file_type = $_FILES[$upload_name]["type"];
$file_err = $_FILES[$upload_name]['error'];
list($width, $height, $type, $attr) = $imageSizeInfo;
$move_me = "images/users/status/".$org_name;
if(move_uploaded_file($file_temp, $move_me)) {
echo "{";
echo "msg: '".$org_name."'";
echo "}";
}
if($width > 604 && $height > 453) {
$jpeg_quality = 90;
$src = "images/users/status/".$org_name;
$ext= pathinfo($src, PATHINFO_EXTENSION);
$targ_h = 453;
$targ_w = 604;
$path_thumbs = "images/users/status/";
$thumb_path = $path_thumbs . '/' . $newfilename;
if($ext == "jpg" OR $ext == "jpeg" OR $ext == "JPG"){
$img_r = imagecreatefromjpeg($src);
}elseif($ext == "png" OR $ext == "PNG"){
$img_r = imagecreatefrompng($src);
}elseif($ext == "gif" OR $ext == "GIF"){
$img_r = imagecreatefromgif($src);
}
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagejpeg($dst_r,$thumb_path,$jpeg_quality);
unlink($move_me);
}
所以首先它上傳與原來的尺寸和一切文件,然後它檢查後的尺寸,然後調整其大小,並取消鏈接(刪除)的原..
現在我不知道是什麼,但不知何故,在調整大小的過程出了問題,我只在尺寸得到一個黑色方形604x453作爲輸出..
我錯過了什麼,我怎麼能解決這個問題?
你應該考慮做更多的輸入過濾,然後只是文件名上的一些「stripslashes」。 – berkes 2011-01-09 15:34:42
@伯克斯,感謝評論,我還應該做些什麼? – Karem 2011-01-09 15:35:44