Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: imagejpeg() [function:imagejpeg]: gd-jpeg: JPEG library reports unrecoverable error

Tags:

php

wordpress

I have wordpress installation on my root folder,

until yesterday it was working fine, but today it gives following error for i guess generating thumbnail images,

Warning: imagejpeg() [function:imagejpeg]: gd-jpeg: JPEG library reports unrecoverable error: in public_html/wp-includes/media.php on line 459

do anyone have any idea regarding this warning??

Please help me

following code is on line 459

if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
like image 972
mack Avatar asked May 16 '12 04:05

mack


5 Answers

You probably tried to create an image from jpeg that is not jpeg.

I got the same error when I was testing a thumbnail script in PHP. Then I found that the header of my input file was png although its extension was .jpg.

So, I edited my script so that if there is an error in creating an image from jpeg, it tries to create it from png (or gif if another error occurs).

like image 125
Web developer BG Avatar answered Oct 03 '22 15:10

Web developer BG


1) Check the space in disk

Your system must have enough disk space

2) Check the memory limit

Set more memory in your php:

ini_set("memory_limit","256M");

3) Check the post_max_size and upload_max_filesize

Set more in your htaccess file:

php_value post_max_size 16M
php_value upload_max_filesize 6M

4) put @ in front of the function

@imagejpeg(..............);

Point 1) worked for me.

like image 39
Fernando Avatar answered Oct 03 '22 17:10

Fernando


You have to use a function to correctly determine mime type of image. A png image that have jpg extension will lead to this error.

To avoid this error, you have to get correct mime type of image.

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;
}
like image 26
Muthu Kumar Avatar answered Oct 03 '22 15:10

Muthu Kumar


I have a Same error .But now i am solved the same issue.

Answer is :We are uploading png and it converts to jpg .
Please check with jpg it works.And we need to convert png to jpg so other functions are available please check on same.

Below code will be useful to convert images using 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);
like image 30
shashik493 Avatar answered Oct 03 '22 16:10

shashik493


On PHP7 imagecreatefromjpeg started throwing fatal errors when you try to open an invalid file, which even the @ sign cannot catch.

Use the following instead:

$im = imagecreatefromstring(file_get_contents($filename));
if ($im !== false) { ... }
like image 37
Simon Epskamp Avatar answered Oct 03 '22 15:10

Simon Epskamp