title: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error - Laravel
body: <p>I have 2 below routes :-</p>
  
  <pre><code>Route::get('resize/avatar', function() {
      $image = 'avatar.jpg';
      $target_filename_here = 'thumbnail_'.$image;
      $ffs = imagecreatefromjpeg($image);
      $size = getimagesize($image);
      $dst = imagecreatetruecolor(100,100);
      $dds = imagecopyresampled($dst,$ffs,0,0,0,0,100,100,$size[0],$size[1]);
      $dn = imagepng($dst,$target_filename_here); // adjust format as needed
      imagedestroy($ffs);
      imagedestroy($dst);
      if($dds) {
          return Redirect::to('color/');
      } else {
          return 'Failed to load the Profile Picture';
      }
  });
  
  
  Route::get('color/', function() {
      if(file_exists('thumbnail_avatar.jpg')) {
          $dest = imagecreatefrompng('transcript.png');
          $fn = imagecreatefromjpeg('thumbnail_avatar.jpg');
          imagecopy($dest, $fn, 550, 830, 0, 0, imagesx($fn), imagesy($fn));
          imagejpeg($dest,"test4.jpg",90);
          imagedestroy($dest);
          imagedestroy($fn);
          return HTML::image('test4.jpg');
      } else {
          return Redirect::to('resize/avatar');
      }
  });
  </code></pre>
  
  <p>And i am getting error as title, I am trying to figure it out, where i am creating an issue, but cannot find it.</p>
  
  <p>My Framework, that i am using is "Laravel 4.2" , but i am pretty sure, it has nothing to do with the framework, as functions are pure php.</p>
  
  <h2>for TL;DR</h2>
  
  <p>I am trying to create thumbnail of profile picture, and than merging it to another image. While doing that, I am getting :- <code>imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error:</code></p>
  
  <p>I have already searched stackoverflow and google for error like mine, but i am unable to find and debug.</p>
  
  <p><strong>Update :</strong>
  <img src="https://i.stack.imgur.com/nC2ZQ.png" alt="enter image description here"></p>
  
  <p>Thanks</p>
  
  <p>FAQ :-</p>
  
  <ol>
  <li><p>Memory Limit ?
  ==> I have sufficient memory.</p></li>
  <li><p>Using "@" in function to hide the error ?
  ==> It doesn't matter. I am still facing this issue.</p></li>
  <li><p>Have you tried another images ?
  ==> Yes, I have tried other images, and i am successful in doing that, it only creates the problem with "generated thumbnail".</p></li>
  </ol>
  
  <p><strong>My Question</strong> Kindly try yourself, using below script for non-laravel :-</p>
  
  <pre><code>function resizeImage() {
      $image = 'avatar.jpg';
      $target_filename_here = 'thumbnail_'.$image;
      $ffs = imagecreatefromjpeg($image);
      $size = getimagesize($image);
      $dst = imagecreatetruecolor(100,100);
      $dds = imagecopyresampled($dst,$ffs,0,0,0,0,100,100,$size[0],$size[1]);
      $dn = imagepng($dst,$target_filename_here); // adjust format as needed
      imagedestroy($ffs);
      imagedestroy($dst);
      if($dds) {
          color();
      } else {
          return 'Failed to load the Profile Picture';
      }
  }
  
  function colorCheck() {
      if(file_exists('thumbnail_avatar.jpg')) {
          $dest = imagecreatefrompng('transcript.png');
          $fn = imagecreatefromjpeg('thumbnail_avatar.jpg');
          imagecopy($dest, $fn, 550, 830, 0, 0, imagesx($fn), imagesy($fn));
              imagejpeg($dest,"test4.jpg",90);
              imagedestroy($dest);
              imagedestroy($fn);
          return HTML::image('test4.jpg');
      } else {
          resizeImage();
      }
  }
  </code></pre>
  
  <p>And you can see the error.</p>
  
  <p>Thanks</p>