(PHP) 图片调整大小失败
(PHP) Image Resize failed
我尝试调整图片大小,但仍然出现相同的错误:
Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 18
Warning: imagecreatefromjpeg(): 'img/test/Bildschirmfoto 2014-01-25 um 08.05.13 nachm Kopie.jpg' is not a valid JPEG file in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 18
Warning: imagesx() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 19
Warning: imagesy() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 20
Notice: A non well formed numeric value encountered in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 24
Notice: A non well formed numeric value encountered in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 24
Warning: imagesx() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 25
Warning: imagesy() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 25
Warning: imagecopyresized() expects parameter 2 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 25
所以,这是我的代码:
function make_thumb($image_path, $thumb_path, $thumb_width) {
$src_img = imagecreatefromjpeg("$image_path");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
$new_w = $thumb_width;
$diff=$origw/$new_w;
$new_h=$new_w;
$dst_img = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, "$thumb_path");
RETURN TRUE;
}
根据您的错误,资源不是有效的 jpg 作为错误状态,之后的错误只是一个链。
我建议您使用我在 PHP image upload, resize and crop called eImage
上写的这个库
试试这个代码:
function make_thumb($image_path, $thumb_path, $thumb_width) {
$src_img = imagecreatefromjpeg("$image_path");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
// This calculations goes is for?
// note that diff is not being used
$new_w = $thumb_width;
$diff = $origw/$new_w;
$new_h = $new_w;
// end of calculation
$canvas = imagecreatetruecolor($new_w,$new_h);
imagecopyresampled($canvas,$src_img,0,0,0,0,$new_w,$new_h,$origw,$origh);
imagejpeg($canvas, $thumb_path);
imagedestroy($src_img);
imagedestroy($canvas);
return true;
}
我尝试调整图片大小,但仍然出现相同的错误:
Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 18
Warning: imagecreatefromjpeg(): 'img/test/Bildschirmfoto 2014-01-25 um 08.05.13 nachm Kopie.jpg' is not a valid JPEG file in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 18
Warning: imagesx() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 19
Warning: imagesy() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 20
Notice: A non well formed numeric value encountered in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 24
Notice: A non well formed numeric value encountered in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 24
Warning: imagesx() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 25
Warning: imagesy() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 25
Warning: imagecopyresized() expects parameter 2 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/dad/gallery.php on line 25
所以,这是我的代码:
function make_thumb($image_path, $thumb_path, $thumb_width) {
$src_img = imagecreatefromjpeg("$image_path");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
$new_w = $thumb_width;
$diff=$origw/$new_w;
$new_h=$new_w;
$dst_img = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, "$thumb_path");
RETURN TRUE;
}
根据您的错误,资源不是有效的 jpg 作为错误状态,之后的错误只是一个链。
我建议您使用我在 PHP image upload, resize and crop called eImage
上写的这个库试试这个代码:
function make_thumb($image_path, $thumb_path, $thumb_width) {
$src_img = imagecreatefromjpeg("$image_path");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
// This calculations goes is for?
// note that diff is not being used
$new_w = $thumb_width;
$diff = $origw/$new_w;
$new_h = $new_w;
// end of calculation
$canvas = imagecreatetruecolor($new_w,$new_h);
imagecopyresampled($canvas,$src_img,0,0,0,0,$new_w,$new_h,$origw,$origh);
imagejpeg($canvas, $thumb_path);
imagedestroy($src_img);
imagedestroy($canvas);
return true;
}