我正在尝试在php中的while循环中重新调整大小,但我一直收到错误,如:
Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in C:\Users\Bob\xampp\htdocs\house\allphotos.php on line 17
Warning: imagecreatefromjpeg(): 'userphotos/27_1366493160164_BMW.jpg' is not a valid JPEG file in C:\Users\Bob\xampp\htdocs\house\allphotos.php on line 17
Warning: imagecopyresized() expects parameter 2 to be resource, boolean given in C:\Users\Bob\xampp\htdocs\house\allphotos.php on line 27
然后是大量的随机字符......
在下文中,我试图回显出以新尺寸选择的2张照片。
我认为它与$image
有关,我没有正确使用该功能吗?
ini_set("gd.jpeg_ignore_warning", 1); //just added
if ($getphotos->execute()){
while ($array = $getphotos->fetch(PDO::FETCH_ASSOC)){
$image = imagecreatefromjpeg('userphotos/'.$array['photoname'].'');
list($image_width, $image_height, $type, $attr) = getimagesize('userphotos/'.$array['photoname'].'');
$new_size = ($image_width + $image_height)/($image_width*($image_height/100));
$new_width = $image_width * $new_size;
$new_height = $image_height * $new_size;
$new_image = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
$imagearray = imagejpeg($new_image, null);
echo $imagearray;
//echo '<img src="userphotos/'.$array['photoname'].'">';
}
} else { die('Query Error'); }
答案 0 :(得分:2)
ini_set("gd.jpeg_ignore_warning", 1);
这将使处理继续,并忽略警告。您的图片很可能仍然可以毫无问题地进行处理。