林當用戶上傳,並嘗試對裁剪PNG或透明圖像(名爲.gif)PHP:作物PNG,反有問題
我越來越:
Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in statusUpFunctions.php on line 100
Warning: imagecreatefromjpeg(): 'images/status/photo/1-6.jpg' is not a valid JPEG file in statusUpFunctions.php on line 100
Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in statusUpFunctions.php on line 114
這可能是因爲我的PHP作物功能:
case 'crop':
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
ini_set('memory_limit', '256M');
$jpeg_quality = 90;
$src = "images/status/photo/".$_POST['fname'];
$img_r = imagecreatefromjpeg($src);
if($_POST['fixed'] == 0) {
$targ_w = $_POST['w'];
$targ_h = $_POST['h'];
}
else {
$targ_h = $_POST['sizeh'];
$targ_w = $_POST['sizew'];
}
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
$path_thumbs = "images/status/photo";
$filename = $newfilename;
$thumb_path = $path_thumbs . '/' . $filename;
imagejpeg($dst_r,$thumb_path,$jpeg_quality);
}
break;
}
從JPG造成的,我不能這樣做從GIF和PNG和BMP創建等..?然後以某種方式轉換它。
這應該如何解決?
嗨感謝你的答案。我如何檢測文件擴展名? $ _POST [ 'FNAME'];是文件名,例如asddsa.jpg – Johnson 2010-10-31 23:57:29
一個非常簡單的方法是查看strpos($ _ POST ['fname'],'.jpg');返回true。只需將'.jpg'更改爲'.png','。gif','。jpeg'即可測試其他類型。 – Klinky 2010-11-01 00:08:26