[英]Getting Error Warning: imagejpeg() [function.imagejpeg]: gd-jpeg: JPEG library reports unrecoverable error
[英]Warning: imagejpeg() [function:imagejpeg]: gd-jpeg: JPEG library reports unrecoverable error
我在我的根文件夹上安装了wordpress,
直到昨天它工作正常,但今天它给出了以下错误,因为我猜生成缩略图,
Warning: imagejpeg() [function:imagejpeg]: gd-jpeg: JPEG library reports unrecoverable error: in public_html/wp-includes/media.php on line 459
有人对这个警告有任何想法吗?
请帮我
以下代码在第459行
if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
您可能尝试从jpeg
创建一个不是jpeg
的图像。
我在PHP中测试缩略图脚本时遇到了同样的错误。 然后我发现输入文件的标题是png
虽然它的扩展名是.jpg
。
因此,我编辑了我的脚本,以便在从jpeg
创建图像时出错,它会尝试从png
创建它(如果发生另一个错误 ,则尝试gif
) 。
1)检查磁盘空间
您的系统必须有足够的磁盘空间
2)检查内存限制
在php中设置更多内存:
ini_set("memory_limit","256M");
3)检查post_max_size和upload_max_filesize
在htaccess文件中设置更多:
php_value post_max_size 16M
php_value upload_max_filesize 6M
4)把@放在函数前面
@imagejpeg(..............);
第1点)为我工作。
我有一个相同的错误。但现在我解决了同样的问题。
答案是:我们正在上传png并将其转换为jpg。
请用jpg检查它是否有效。我们需要将png转换为jpg以便其他功能可用,请检查相同。
下面的代码对使用GD Library转换图像很有用。
//variable declare or parameter use
$originalImage ="1.jpg";
$quality=100; // for jpg good quality
$outputImage; //for source file save.
// jpg, png, gif or bmp?
$exploded = explode('.',$originalImage);
$ext = $exploded[count($exploded) - 1];
if (preg_match('/jpg|jpeg/i',$ext))
$imageTmp=imagecreatefromjpeg($originalImage);
else if (preg_match('/png/i',$ext))
$imageTmp=imagecreatefrompng($originalImage);
else if (preg_match('/gif/i',$ext))
$imageTmp=imagecreatefromgif($originalImage);
else if (preg_match('/bmp/i',$ext))
$imageTmp=imagecreatefrombmp($originalImage);
else
return 0;
// quality is a value from 0 (worst) to 100 (best)
imagejpeg($imageTmp, $outputImage, $quality);
imagedestroy($imageTmp);
您必须使用函数来正确确定mime类型的图像。 具有jpg扩展名的png图像将导致此错误。
要避免此错误,您必须获得正确的mime类型的图像。
function getImage($path) {
switch(mime_content_type($path)) {
case 'image/png':
$img = imagecreatefrompng($path);
break;
case 'image/gif':
$img = imagecreatefromgif($path);
break;
case 'image/jpeg':
$img = imagecreatefromjpeg($path);
break;
case 'image/bmp':
$img = imagecreatefrombmp($path);
break;
default:
$img = null;
}
return $img;
}
在PHP7上,当您尝试打开无效文件时, imagecreatefromjpeg
开始抛出致命错误,即使是@
符号也无法捕获。
请改用以下内容:
$im = imagecreatefromstring(file_get_contents($filename));
if ($im !== false) { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.