25

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' ) ) )
mack
  • 1,768
  • 5
  • 21
  • 28
  • 2
    How are we supported to know what's on line 459? – zerkms May 16 '12 at 04:12
  • Is GD enabled on your site/host?, try adding the following to your .htaccess file: AddType x-mapp-php5 .php AddHandler x-mapp-php5 .php – swapnesh May 16 '12 at 04:21
  • till yesterday it was working fine, i do have cpanel access, how do i check that GD is enabled or not? – mack May 16 '12 at 04:22
  • just run file and chech if GD library is enabled or not, if not change settings in php.ini or use ini_set() method..check this link for further info regarding GD http://assets.webassist.com/how-tos/gd_library_ht.pdf – swapnesh May 16 '12 at 04:24
  • i have referred you pdf link, and GD is enabled in my server – mack May 16 '12 at 04:42
  • No free disk space, or over quota (for WHM/etc) is where we were getting the error from. – Chris Seufert Jun 21 '15 at 23:30

5 Answers5

35

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).

Carl Binalla
  • 5,393
  • 5
  • 27
  • 46
Web developer BG
  • 459
  • 1
  • 4
  • 3
16

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.

Jo.
  • 778
  • 1
  • 12
  • 17
Fernando
  • 1,126
  • 12
  • 13
6

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;
}
Bruno Ribeiro
  • 1,280
  • 16
  • 21
Muthu Kumar
  • 420
  • 5
  • 7
4

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);
ketan
  • 19,129
  • 42
  • 60
  • 98
shashik493
  • 790
  • 1
  • 10
  • 12
4

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) { ... }
Simon Epskamp
  • 8,813
  • 3
  • 53
  • 58