2015-10-15 38 views
1

我想用GD库用symfony,但我有这个错误错误钆图书馆Symfony的

Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error:

我的脚本在我的控制器是

if (extension_loaded('gd') && function_exists('gd_info')) { 
      echo "PHP GD library is enabled in your system."; 
     } 
     else { 
      echo "PHP GD library is not enabled on your system."; 
     } 

     echo phpinfo(); 

     $filename = $this->get('kernel')->getRootDir() . '/../web/logo/logo.png'; 
     $percent = 0.5; 

// Content type 
//  header('Content-Type: image/jpeg'); 

// Get new sizes 
     list($width, $height) = getimagesize($filename); 
     $newwidth = $width * $percent; 
     $newheight = $height * $percent; 

// Load 
     $thumb = imagecreatetruecolor($newwidth, $newheight); 
     $source = imagecreatefromjpeg($filename); 

// Resize 
     imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 

// Output 
     imagejpeg($thumb); 

     return new Response("foo"); 

在我的phpinfo我可以看到GD库。

我使用MAMP 3.2.1

+1

[可怕的可能重复 “警告:imagecreatefromjpeg() '/ tmp目录/文件名' 不/phpfile.php有效的JPEG文件就行XXX” ](http://stackoverflow.com/questions/3901455/the-dreaded-warning-imagecreatefromjpeg-tmp-filename-is-not-a-valid-jpe) – jahller

回答

2

这是GD库中的已知的问题并没有涉及到Symfony的。 GD对于JPEG文件的格式非常严格,因为它只接受非常特定的JPEG配置。

这个问题有很多资源。例如。 http://php.net/manual/de/function.imagecreatefromjpeg.php#55402

If you get this error: "Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error" then check the JPEG files. If they are saved in CMYK format (instead of RGB) then GD will fail to load them (tested with GD 2.0.12)

the dreaded "Warning: imagecreatefromjpeg() : '/tmp/filename' is not a valid JPEG file in /phpfile.php on line xxx"

It seems that the GD library is less tolerant of buggy JPEG files than other programs. The solution suggested was to set GD to ignore JPEG error's before processing the image, like this:

ini_set("gd.jpeg_ignore_warning", 1);