我正在尝试在 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'); }